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.

Error using jsdom with Node 7.4.0

See original GitHub issue

I am working on a project that uses mocha with jsdom and enzyme to run our integration tests within a virtual dom in Node. Right now I am using node 6.9.2, and everything works fine. I tried using 7.4.0, however running the tests I got the error

SyntaxError
    at XMLHttpRequest.open (/Users/jake/metamason/react-frontend/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:458:15)
    at XMLHttpRequest.tryCatcher (/Users/jake/metamason/react-frontend/node_modules/rxjs/src/util/tryCatch.ts:7:27)
    at AjaxSubscriber.send (/Users/jake/metamason/react-frontend/node_modules/rxjs/src/observable/dom/AjaxObservable.ts:232:37)
    at new AjaxSubscriber (/Users/jake/metamason/react-frontend/node_modules/rxjs/src/observable/dom/AjaxObservable.ts:203:10)
    at AjaxObservable._subscribe (/Users/jake/metamason/react-frontend/node_modules/rxjs/src/observable/dom/AjaxObservable.ts:172:12)

I haven’t really done any investigation into the root cause of this, but I thought I’d let you know what I saw. Here’s the testHelper file that I use to set things up:

const chai = require('chai');
const chaiImmutable = require('chai-immutable');
const jsdom = require('jsdom').jsdom;

// Set Chai Immutable
chai.use(chaiImmutable);

// Set up jsdom
global.document = jsdom('<html><body><div id="app"></div></body></html>', {
    url: 'http://example.com',
});

global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
    if (typeof global[property] === 'undefined') {
        global[property] = document.defaultView[property];
    }
});

global.navigator = {
    userAgent: 'node.js',
};

window.sessionStorage = window.localStorage = {
    getItem() {},
    setItem() {},
    removeItem() {},
};
// jsdom doesn't have an implementation for this because they don't do layout.
// I opened an issue, and they might add a stub in the future with a warning
// Needed because the grommet Drop util was calling it for Menu components
window.HTMLElement.prototype.scrollIntoView = function() {};

window.performance = require('./helpers/performanceNowPolyfill')();

Let me know if you need any more info!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ayxoscommented, May 19, 2017

Not working on 7.9.0! 😦

2reactions
domeniccommented, Feb 1, 2017

Yeah, there was a regression in v7.4.0. There are still some issues left, but maybe you’re not hitting them as much. In general see https://github.com/nodejs/node/issues/6283 for a list of all the potential issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsdom - npm
jsdom. jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node.js.
Read more >
How to import d3.js in a node and typescript project ...
I made the function that generates the document async and added that line at the start but nope. Anyway, if I believe the...
Read more >
require is not defined babel | The AI Search Engine You Control
Issue npm run start to bring up webpack-dev-server at port 9000. ... If you are using Babel 7.4.0 or newer, then @babel/polyfill has...
Read more >
CLI install on Linux Mint 19.3 - Support - Joplin Forum
I tried installing the CLI, but failed. On my desktop I already have Joplin 1.3.18 working. I was not sure if it is...
Read more >
Release Notes | Firebase - Google
This release includes a bug fix in Crashlytics. October 17, 2022. SDK Releases. The Firebase Admin Node.
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