1 回答

TA贡献1872条经验 获得超3个赞
我的第二项测试设置为始终为真。我称这个功能
wrapper.vm.input()
然后断言它将被调用,这将是正确的,因此它是一个不好的测试。
input.trigger('change')
...是正确的,那正是我拥有的地方。这是我的重构测试:
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()
})
})
添加回答
举报