【问题标题】:Importing the Nock npm module creates error when running npm test运行 npm test 时导入 Nock npm 模块会产生错误
【发布时间】:2016-06-15 21:49:51
【问题描述】:

如果我删除 nock 导入,我不会收到错误消息。我已经安装了 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)

【问题讨论】:

    标签: javascript node.js npm nock


    【解决方案1】:

    我不知道我的项目使用的是 Jest 测试框架, 随后需要在导入之前通过 jest.unmock('nock'); 来“取消模拟”模块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 2019-11-20
      • 2019-03-31
      相关资源
      最近更新 更多