【发布时间】:2019-09-26 09:06:07
【问题描述】:
我在我的测试文件中创建了一个商店
import {
shallowMount,
createLocalVue
} from '@vue/test-utils'
import Vuex from 'vuex'
import Actions from '../../../src/components/Actions'
const localVue = createLocalVue()
localVue.use(Vuex)
describe('Actions.vue', () => {
let actions
let store
beforeEach(() => {
actions = {
actionClick: jest.fn(() => Promise.resolve({}))
}
store = new Vuex.Store({
actions
})
})
it('should go to then block', () => {
const wrapper = shallowMount(Actions, {
store,
localVue
})
//goes to then block
})
it('should go to catch block', () => {
actions.actionClick = jest.fn(() => Promise.reject(new Error()))
const wrapper = shallowMount(Actions, {
store,
localVue
})
//still goes to then block and not the catch block
})
})
根据上面的代码,我无法实现第二个测试块意味着它没有修改存储中的 actionClick 函数。
【问题讨论】:
标签: vue.js vuejs2 jestjs vuex vue-test-utils