1 回答

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
我的第二項(xiàng)測(cè)試設(shè)置為始終為真。我稱這個(gè)功能
wrapper.vm.input()
然后斷言它將被調(diào)用,這將是正確的,因此它是一個(gè)不好的測(cè)試。
input.trigger('change')
...是正確的,那正是我擁有的地方。這是我的重構(gòu)測(cè)試:
describe('when the checkbox state is changed', () => {
let input
beforeEach(() => {
input = wrapper.find('input')
jest.spyOn(wrapper.vm, 'input')
jest.runAllTimers()
})
it('[positive] should emit an input event with the input\'s value', () => {
input.trigger('change')
expect(wrapper.emitted().input).toBeTruthy()
expect(wrapper.emitted().input).toHaveLength(1)
expect(wrapper.emitted().input[0]).toEqual([false])
})
it('[negative] should not emit an input event with the input\'s value', () => {
input.trigger('input')
expect(wrapper.emitted().input).toBeFalsy()
})
})
添加回答
舉報(bào)