[Vuejs]-Adding Props to found components throw the mounted wrapper

0👍

The answer is that you should not do that. Because BaseSelector should have it’s own tests in which you should test behavior changes through the setProps.

But if you can’t do this for some reason, here what you can do:

  1. Check the props passed to BaseSelector. They always depend on some reactive data (props, data, or computed)
  2. Change those data in MyForm instead.

For example

// MyForm.vue
data() {
  return {
    servicePicker: {data: null}
  }
}

// test.js
wrapper = mount(MyForm)
wrapper.setData({servicePicker: {data: [...some data]})
expect(wrapper.findComponent(BaseSelector)).toDoSomething()

But I suggest you to cover the behavior of BaseSelector in separate test by changing it’s props or data. And then in the MyForm‘s test you should just check the passed props to BaseSelector

expect(wrapper.findComponent(BaseSelector).props('options')).toEqual(expected)

Leave a comment