【发布时间】:2020-09-30 09:58:22
【问题描述】:
我正在阅读 Vue Testing Cookbook 和 Vue Test Utils's docs,他们在其中涉及使用 Vuex 测试组件。两个消息来源都建议使用createLocalVue,但我不完全理解为什么。我们已经有几个使用 Vuex 但不使用 createLocalVue 的测试,它们可以工作。 那么为什么这些消息来源建议使用createLocalVue?
根据这些来源,这里的测试似乎是一种不好的做法。这段代码会在未来破坏一些东西吗?它是否会导致我们不知道的不良副作用?
import { mount } from '@vue/test-utils';
import Vuex from 'vuex';
import Component from 'somewhere';
// We don't use this and yet the code seems to work
// const localVue = createLocalVue()
// localVue.use(Vuex)
describe('Foo Component', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Component, {
// localVue, <-- We don't use this
store: new Vuex.Store({
modules: {
app: {
namespaced: true,
// ... more store stuff
}
}
})
})
});
it('should contain foo', () => {
expect(wrapper.contains('.foo')).toBe(true);
});
});
【问题讨论】:
标签: unit-testing vue.js vuex vue-test-utils