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.

Allow passing config to jsdom.env

See original GitHub issue

Example with jsdom:

var jsdom = require("jsdom");

jsdom.env({
  userAgent: 'Some user agent'
});

Possible solution


require('node-browser-environment')({
  // props: ['window', 'document', 'navigator'],
  userAgent: 'Some user agent'
});

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
fregantecommented, Jun 20, 2016

LGTM, Thanks!

0reactions
lukechildscommented, Jun 19, 2016

Ok, I decided to remove the overwrite option, I’m checking any conflicts between the jsdom window properties and global node properties when the module is loaded and blacklisting them to stop weird bugs. This means all the other properties can be safely overwritten every time so there’s no need for an option to opt in.

I’ve replaced the overwrite arg with the jsdom config arg so it can be used like this:

require('node-browser-environment')(['window'], { userAgent: 'My User Agent' });

It can also be used on it’s own without the properties arg:

require('node-browser-environment')({ userAgent: 'My User Agent' });

It’s a breaking API change so I’ve published as v2. You’ll need to manually bump the version in your package.json to get the new functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to config jest jsdom environment? - Stack Overflow
In my case, the solution was: Install this package: jest-environment-jsdom; Add testEnvironment: 'jest-environment-jsdom' into my ...
Read more >
Configuring Jest
Configuring Jest. Jest's configuration can be defined in the package.json file of your project, or through a jest.config.js file or through ...
Read more >
Add testEnvironmentOptions to apply to jsdom options or node ...
The new test is failing CI. I'm wondering if one should key the config per environment? Is it an issue that jsdom options...
Read more >
jest-environment-jsdom | Yarn - Package Manager
... for jsdom environment (#11924); [jest-environment-jsdom] [BREAKING] Pass global config to Jest environment constructor for jsdom environment (#12461) ...
Read more >
jsdom - npm
jsdom.env is an API that allows you to throw a bunch of stuff at it, ... If you would like to specify a...
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