1

错误:

expect(actual).toHaveBeenCalled() 中的“实际”参数必须是间谍

最小的不工作示例:

const mockFn = jest.fn();
mockFn();
expect(mockFn).toHaveBeenCalled();

问:jest.fn()不是间谍?

4

1 回答 1

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();
  });
于 2018-11-04T13:35:28.157 回答