如何让nock在反应和单元测试中工作?

时间:2017-09-29 04:10:47

标签: unit-testing react-redux nock

我正在查看单元测试redux动作创建者的this链接:。这是我的单元测试的样子:

 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模块,但为什么我会收到此错误,如何摆脱这个?

0 个答案:

没有答案