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:
- You can use createLocalVue, and register a mixin on that localVue class:
const localVue = createLocalVue()
localVue.mixin(myMixin)
const wrapper = shallow(Post, {
localVue,
})
- You can pass
mixins
in the mounting options:
const wrapper = shallow(Post, {
mixins: [myMixin],
})