question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing the Nock npm module creates error when running npm test

See original GitHub issue

If I remove the nock import I won’t get an error message. I’ve already npm installed nock.

Test file

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)

Error Message

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)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
tylerchildscommented, Aug 4, 2016

Also confirming I was able to resolve this by putting this my package.json file:

  "jest": {
    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/nock",
      "<rootDir>/node_modules/redux-thunk",
      "<rootDir>/node_modules/redux-mock-store",
    ]
  }
2reactions
dannyidcommented, Jun 27, 2016

I’m having the same problem. If you’re using Jest, I believe you need to unmock these modules before using them because Jest will automock everything.

At the top of your file, add:

jest.unmock('nock');
jest.unmock('redux-mock-store');
jest.unmock('redux-thunk');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing the Nock npm module creates error when running ...
I've already npm installed nock . Test file. import configureMockStore from 'redux-mock-store' import { promiseHandler } from ...
Read more >
nock - npm
HTTP server mocking and expectations library for Node.js. Nock can be used to test modules that perform HTTP requests in isolation.
Read more >
API mock testing with Nock for Node.js apps - LogRocket Blog
In this quick tutorial, learn how to make mock HTTP requests with Nock to test your Node.js application's API endpoints.
Read more >
Testing Error Handling in node.js | by Lars Trieloff
json 's test script, I set up nyc , which generates test coverage reports with the following options: --reporter=text creates a nice textual...
Read more >
Mocking External HTTP Requests in Node Tests with Nock
Avoid the challenges of testing Node.js code that depends on external services and APIs by using Nock to test HTTP requests in isolation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found