How to mock Vue Mixins during unit testing using v

2019-02-17 16:36发布

问题:

I read vue-utils-test documentation 3 times and documentation of jest too, But I do not get idea how exactly mock the vue mixins in vue component and test the component.

回答1:

There are two ways:

  1. You can use createLocalVue, and register a mixin on that localVue class:
const localVue = createLocalVue()
localVue.mixin(myMixin)

const wrapper = shallow(Post, {
    localVue,
})
  1. You can pass mixins in the mounting options:
const wrapper = shallow(Post, {
    mixins: [myMixin],
})