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.

Nock doesn't work with the latest version of jsdom

See original GitHub issue

Jsdom has updated the way they implement XMLHttpRequest in version 8.2.0. My test suite sets up jsdom for some (unrelated to nock) UI tests. With version 8.2.0 of jsdom installed nock fails to mock requests (they actually hit the network). Version 8.1.0 works fine. Tested with version 7.7.2 of nock.

cc @domenic, @nicolashenry from jsdom.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
ryanjuve-porchcommented, May 16, 2016

@kwhitaker for my use case I use a url (front.dev.porch.com) that redirects to localhost via my hosts file. So my jsdom call is:

jsdom.jsdom('<!doctype html><html><body></body></html>', {
    url: 'http://front.dev.porch.com:9339'
});

Then hitting http://front.dev.porch.com:9339/foo/service/route worked within my tests. I did need to use nock.recorder.rec() to get the EXACT nock calls necessary for intercepting to work, just FYI.

0reactions
lock[bot]commented, Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React API test with Nock failing with "Error - node.js
If you're using jest + react, your jest config sets the testEnviromnent to jsdom . But nock requires a node environment to mock...
Read more >
Jest 27: New Defaults for Jest, 2021 edition
In the Jest 26 blog post about a year ago, we announced that after two major releases with few breaking changes, Jest 27...
Read more >
Stop mocking fetch - Kent C. Dodds
But, one issue with this is because you're mocking out the client , how do you really know the client is being used...
Read more >
nock: disallowed net connect - You.com | The search engine you ...
probot/probotProbot (Nock) Unit Tests Not Working with Github Enterprise#928 ... Probot version(s): 7.5.3; Node/npm version: node 8.12 npm 6.4.1 ...
Read more >
When JSDOM for testing UI is not enough - Level Up Coding
JSDOM is a pure javascript implementation of the DOM so it's not even designed ... With Playwright you can run the last version...
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