0

我正在查看指向单元测试 redux 操作创建者的链接:. 这是我的单元测试的样子:

 it('creates FETCH_TODOS_SUCCESS when fetching todos has been done', () => {
    nock('http://example.com/')
      .get('/todos')
      .reply(200, { body: { todos: ['do something'] } })

    const expectedActions = [
      { type: 'fetch_todos_request' },
      { type: 'fetch_todos_success', body: { todos: ['do something'] } }
    ]
    const store = mockStore({ todos: [] })

    return store.dispatch(actions.fetchTodos()).then(() => {
      // return of async actions
      expect(store.getActions()).toEqual(expectedActions)
    })
  })

在我开玩笑的解决方案中,我使用 react+typescript。我有一种直觉,我的错误与打字稿配置有关,这是错误:

src\__tests__\redux-test.tsx
  ● async actions › creates FETCH_TODOS_SUCCESS when fetching todos has been done

    TypeError: nock_1.default is not a function

      at Object.it (src/__tests__/redux-test.tsx:17:9)
      at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
      at process._tickCallback (internal/process/next_tick.js:109:7)

nock 模块已安装,但为什么会出现此错误,如何摆脱此错误?

4

0 回答 0