我的涉及模拟功能(反应,酶和笑话)的测试有效:
it('should do a thing', () => {
const myButton = wrapper.find('Button');
expect(mockFunction.mock.calls.length).toBe(0);
myButton.simulate('click');
expect(mockFunction.mock.calls.length).toBe(1);
});
但是,当我尝试使用变量简化代码时,测试将失败。 numberClicks
两次都是0
。
it('should do a thing', () => {
const myButton = wrapper.find('Button');
const numberClicks = mockFunction.mock.calls.length;
expect(numberClicks).toBe(0);
myButton.simulate('click');
expect(numberClicks).toBe(1);
});
这是正常的JavaScript行为还是测试库有些怪异?