小编Fra*_*ker的帖子

jest 函数必须是模拟或间谍

我正在编写一个测试,测试我的应用程序中的操作。我在尝试拨打最后一个电话时遇到了麻烦。

const pushData = jest.fn(() => Promise.resolve());

test('anotherAsyncCall is fired to get more info', () => {
  const store = mockStore({});
  asynCallToGetData = jest.fn(() => Promise.resolve());

  const action = pushData();
  const dispatch = jest.fn();
  const anotherAsyncCall = jest.fn(() => Promise.resolve());

  const expectedActions = [{
    type: 'DATA_RECEIVED_SUCCESS'
  }];

  return store.dispatch(action).then(() => {
    expect(asynCallToGetData).toHaveBeenCalled();
    expect(store.getActions()).toMatch(expectedActions[0].type);
    expect(dispatch(anotherAsyncCall)).toHaveBeenCalled(); //This fails
  });
});
Run Code Online (Sandbox Code Playgroud)

但运行测试后我收到的消息是

expect(jest.fn())[.not].toHaveBeenCalled()

jest.fn() value must be a mock function or spy.
  Received: undefined here
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs redux enzyme

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

enzyme ×1

javascript ×1

jestjs ×1

reactjs ×1

redux ×1