运行 npm test 时导入 Nock npm 模块会产生错误

Importing the Nock npm module creates error when running npm test

如果我删除箭尾导入,我将不会收到错误消息。我已经安装了 npm nock.

测试文件

import configureMockStore from 'redux-mock-store'
import { promiseHandler } from '../middleware'
import * as actions from './index'
import nock from 'nock'
import expect from 'expect'

const middlewares = [promiseHandler]
const mockStore = configureMockStore(middlewares)

错误信息

 FAIL  src/actions/index.test.js
Runtime Error
  - TypeError: debug is not a function
        at overrideClientRequest (node_modules/nock/lib/intercept.js:221:3)
        at activate (node_modules/nock/lib/intercept.js:320:3)
        at Object.<anonymous> (node_modules/nock/lib/intercept.js:383:1)
        at Runtime._execModule (node_modules/jest-cli/src/Runtime/Runtime.js:261:17)
        at Object.<anonymous> (node_modules/nock/lib/recorder.js:6:17)
        at Object.<anonymous> (node_modules/nock/index.js:1:135)
        at Object.<anonymous> (src/actions/index.test.js:4:39)
        at jasmine2 (node_modules/jest-jasmine2/src/index.js:252:16)
        at handle (node_modules/worker-farm/lib/child/index.js:41:8)
        at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:47:3)
        at emitTwo (events.js:100:13)
        at process.emit (events.js:185:7)
        at handleMessage (internal/child_process.js:718:10)
        at Pipe.channel.onread (internal/child_process.js:444:11)

我不知道我的项目正在使用 Jest 测试框架, 随后,模块需要通过在导入之前执行 jest.unmock('nock'); 来 "unmocked"。