我对 Vue 组件的单元测试很少。在大多数测试中, shallowMounted 组件只需要计算属性。但是对于两个测试,我需要一个 store(Vuex) 实例。有没有办法将实例添加到已经很浅的组件中?可能是下面的代码将有助于理解。它只是一个例子。谢谢你。
describe(('Vue component test') => {
beforeEach(() => {
wrapper = shallowMount(Component, {
computed: {
errors: () => null,
isLoading: () => false,
}
})
});
describe('Test 1', => {
it('is a vue instance', () => {
expect(wrapper...);
});
});
describe('Test 2' => {
it('is a vue component', () => {
expect(wrapper...);
});
})
describe('Test with store instance', {
// Add store(Vuex) instance to the `wrapper` defined inside beforeEach() above
// Then use the wrapper
expect(wrapper...);
});
});