1.0.0-beta.24
https://codesandbox.io/s/pjlwznqq1m
propsDataprops are passed to the component
no props are passed to the component
You can only test a functional component with context.props, not with propsData as with other components, which means that what used to be an internal implementation detail (what kind of component it is) becomes public API for the tests now and needs to be changed if that component changes of type. See what I expected to work in the first assertion, and what eventually worked in the second assertion. I didn't find anything about this in the docs.
import { mount } from '@vue/test-utils';
import FunctionalComponent from './FunctionalComponent';
it("doesn't allow you to pass propsData", () => {
// this doesn't work but I'd like it to
const wrapper = mount(FunctionalComponent, {
propsData: {
someProp: 'hi there',
},
});
expect(wrapper.html()).toMatchSnapshot();
});
it('only allows you to pass context', () => {
const wrapper = mount(FunctionalComponent, {
context: {
props: {
someProp: 'hi there',
},
},
});
expect(wrapper.html()).toMatchSnapshot();
});
Could we have a props option which delegates to either propsData or context.props depending on what type of component is being mounted?
Hi, updating documentation can save poor little fellows time. It took me almost an hour that it's actually an issue belongs to vue-test-utils.
Any solution?
a functional component works like the second example test in my post
I am going to take responsibility for this. I think we should do to things
If it turns out we cannot detect if a component is functional or not, I'll abandon (2) and just do (1).
Thanks @lmiller1990, that sounds like a great resolution to me!
@Haroenv so it looks like this is actually fixed? Upgrading your reproduction repro to beta-30 (or beta-29, looks like beta-28 broke this) shows all green.
Going to close this one, unless I missed something. Googlers, update your version of vue-test-utils to the latest (if possible) or at least beta-29.
I wasn't aware this was fixed, this is great news @lmiller1990, thanks!
Most helpful comment
Could we have a
propsoption which delegates to eitherpropsDataorcontext.propsdepending on what type of component is being mounted?