错误:
"实际" expect(actual)中的参数.toHaveBeenCalled()必须是间谍
最小的不工作示例:
const mockFn = jest.fn();
mockFn();
expect(mockFn).toHaveBeenCalled();
问题: jest.fn()
不是间谍?
答案 0 :(得分:0)
我尝试了以下对我有用的实现
it("should call mock function when button is clicked", () => {
const mockFn = jest.fn();
const tree = shallow(<button name="button test" handleHandler={mockFn} />);
tree.simulate("click");
mockFn();
expect(mockFn).toHaveBeenCalled();
});