simon360 / jest-environment-jsdom-global Goto Github PK
View Code? Open in Web Editor NEWA Jest environment that allows you to configure jsdom
License: MIT License
A Jest environment that allows you to configure jsdom
License: MIT License
Unfortunately I cannot use both this and https://github.com/ianschmitz/jest-environment-jsdom-fourteen. Any idea for a solution?
For some reason, jsdom
isn't defined when I run my tests with this environment. Per the documentation, I used global.jsdom
instead, and then it says global.jsdom
is undefined.
I'm trying to use jsdom.reconfigure
to change the URL in one of my tests.
Version 1.0.2 is live on npm
, but the commits never made it into GitHub. Put the commit and tag in the correct place in the commit history.
(These are sitting on my laptop at home. Will take care of this as soon as I'm back post-holidays)
I receive the following error when running my tests:
Error: Not implemented: navigation (except hash changes)
at module.exports (...\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
at navigateFetch (...\node_modules\jsdom\lib\jsdom\living\window\navigation.js:74:3)
at exports.navigate (...\node_modules\jsdom\lib\jsdom\living\window\navigation.js:52:3)
at LocationImpl._locationObjectNavigate (...\node_modules\jsdom\lib\jsdom\living\window\Location-impl.js:29:5)
at LocationImpl._locationObjectSetterNavigate (...\node_modules\jsdom\lib\jsdom\living\window\Location-impl.js:23:17)
at LocationImpl.set pathname [as pathname] (...\node_modules\jsdom\lib\jsdom\living\window\Location-impl.js:151:10)
at Location.set [as pathname] (...\node_modules\jsdom\lib\jsdom\living\generated\Location.js:293:31)
at Object.it (...\src\services\sub-services\supported-browser-service\test\supported-browser-service.spec.js:52:38)
at Object.asyncJestTest (...\node_modules\jest-jasmine2\build\jasmine_async.js:108:37)
at resolve (...\node_modules\jest-jasmine2\build\queue_runner.js:56:12) undefined
I've tried the following two methods of dynamically updating my URL but I still receive the error:
global.jsdom.reconfigure({
url: `https://www.${hostname}`
});
and
jsdom.reconfigure({
url: `https://www.${hostname}`
});
The tests still pass for some reason, just curious if this is something I should be concerned about?
NOTE:
Here are my dependencies in package.json
:
{
...
,
"dependencies": {
"axios": "0.18.0",
"bowser": "2.0.0-beta.3",
"classnames": "2.2.6",
"dashjs": "2.9.2",
"get-countries-info": "1.2.1",
"lodash": "4.17.11",
"moment": "2.22.2",
"nuka-carousel": "4.3.5",
"prop-types": "15.6.2",
"querystringify": "2.0.0",
"rc-slider": "8.6.3",
"react": "16.5.2",
"react-custom-scrollbars": "4.2.1",
"react-dom": "16.5.2",
"react-icons-kit": "1.1.7",
"react-image-fallback": "8.0.0",
"react-lottie": "1.2.3",
"react-markdown": "3.6.0",
"react-player-controls": "0.5.21",
"react-redux": "5.0.7",
"react-router-dom": "4.3.1",
"react-select": "2.0.0",
"react-toastify": "3.4.3",
"redux": "4.0.1",
"redux-promise": "0.6.0",
"redux-thunk": "2.3.0",
"validator": "10.7.1"
},
"devDependencies": {
"autoprefixer": "9.1.5",
"babel-core": "6.26.3",
"babel-eslint": "9.0.0",
"babel-jest": "23.6.0",
"babel-loader": "7.1.2",
"babel-preset-react-app": "3.1.2",
"babel-runtime": "6.26.0",
"case-sensitive-paths-webpack-plugin": "2.1.2",
"chalk": "2.4.1",
"css-loader": "1.0.0",
"dotenv": "6.0.0",
"dotenv-expand": "4.2.0",
"enzyme": "3.7.0",
"enzyme-adapter-react-16": "1.6.0",
"enzyme-matchers": "6.0.4",
"eslint": "4.19.1",
"eslint-config-prettier": "3.0.1",
"eslint-config-react-app": "2.1.0",
"eslint-loader": "2.1.1",
"eslint-plugin-flowtype": "2.50.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jest": "21.25.1",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-prettier": "3.0.0",
"eslint-plugin-react": "7.11.1",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "2.0.0",
"fs-extra": "7.0.0",
"generate-react-code": "1.3.0",
"html-webpack-plugin": "3.2.0",
"husky": "0.14.3",
"jest": "23.6.0",
"jest-environment-jsdom": "23.4.0",
"jest-environment-jsdom-global": "1.1.0",
"jest-enzyme": "7.0.0",
"jest-localstorage-mock": "2.2.0",
"jest-mock-console": "0.4.0",
"lint-staged": "7.3.0",
"moxios": "0.4.0",
"node-sass-chokidar": "1.3.3",
"npm-run-all": "4.1.3",
"object-assign": "4.1.1",
"postcss-flexbugs-fixes": "4.1.0",
"postcss-loader": "3.0.0",
"prettier": "1.14.3",
"promise": "8.0.2",
"raf": "3.4.0",
"react-dev-utils": "5.0.2",
"react-redux-mock": "0.2.2",
"redux-devtools-extension": "2.13.5",
"redux-logger": "3.0.6",
"resolve": "1.8.1",
"style-loader": "0.23.0",
"sw-precache-webpack-plugin": "0.11.5",
"url-loader": "1.1.1",
"webpack": "3.12.0",
"webpack-dev-server": "2.11.3",
"webpack-manifest-plugin": "2.0.3",
"whatwg-fetch": "2.0.4"
},
....
}
Here is my jest-setup.json
file:
{
"collectCoverageFrom": ["**/*.js"],
"setupFiles": ["<rootDir>/config/polyfills.js", "jest-localstorage-mock"],
"setupTestFrameworkScriptFile": "<rootDir>/jest-setup/setup-tests.js",
"testMatch": ["<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"],
"testEnvironment": "jest-environment-jsdom-global",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/css-transform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/file-transform.js"
},
"transformIgnorePatterns": ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"],
"moduleFileExtensions": ["web.js", "js", "json", "web.jsx", "jsx", "node", "mjs"],
"coverageThreshold": {
"global": {
"statements": 99,
"branches": 99,
"functions": 99,
"lines": 99
}
}
}
error "jest-environment-jsdom-global#[email protected] || 23.x" doesn't satisfy found match of "[email protected]"
Jest 26 is out, which means installing this package results in this kind of warning:
warning " > [email protected]" has incorrect peer dependency "[email protected] || 23.x || 24.x || 25.x".
I've tried:
import * as jsdom from 'jest-environment-jsdom-global';
and
import jsdom from 'jest-environment-jsdom-global';
Code Excerpt:
import * as isActive from './activity-functions';
import jsdom from 'jest-environment-jsdom-global';
describe('activity functions', () => {
it('verifies that the navbar is always active', () => {
jsdom.reconfigure({
url: "https://localhost/navbar",
});
......
Package.json
....
"jest": "^25.2.7",
"jest-cli": "^25.2.7",
"jest-environment-jsdom": "^26.1.0",
"jest-environment-jsdom-global": "^2.0.4",
"lint-staged": "^10.2.7",
"prettier": "^2.0.5",
...
Jest Config
"jest": {
"testEnvironment": "jest-environment-jsdom-global",
"coverageReporters": [
"text",
"text-summary"
]
}
Error:
activity functions › verifies that the navbar is always active
TypeError: _jestEnvironmentJsdomGlobal.default.reconfigure is not a function
4 | describe('activity functions', () => {
5 | it('verifies that the navbar is always active', () => {
> 6 | jsdom.reconfigure({
| ^
This week, I upgraded jest-environment-jsdom from 26.6.2 to 27.0.3 and I'm now seeing some issues that I believe are related to this package. If I run multiple test files at once, everything is fine, but if I run a single test file, then there's a crash in this package:
● Test suite failed to run
evalmachine.<anonymous>:1
AggregateError
^
ReferenceError: AggregateError is not defined
at evalmachine.<anonymous>:1:1
at setupWindow (node_modules/jsdom/lib/jsdom/browser/Window.js:111:55)
at new Window (node_modules/jsdom/lib/jsdom/browser/Window.js:223:3)
at exports.createWindow (node_modules/jsdom/lib/jsdom/browser/Window.js:95:10)
at new JSDOM (node_modules/jsdom/lib/api.js:36:20)
at new JSDOMEnvironmentGlobal (node_modules/jest-environment-jsdom-global/environment.js:12:5)
I think issue #46 is related.
hello simon
In my project jest-environment-jsdom-global can run normally,
But jslint will prompt me 'Cannot find name 'jsdom'
my tslint version is "^5.10.0"
,should i ignore this waring?
Currently, this warning is appearing during yarn install
if you install Jest 25:
warning " > [email protected]" has incorrect peer dependency "[email protected] || 23.x || 24.x".
I am trying to use this to mock localStorage:
const localStorage = {
getItem: jest.fn().mockReturnValue(JSON.stringify({
BUILD_DATE: DATE
}))
};
jsdom.reconfigure({
localStorage
});
However it doesn't appear to work. Is mocking localStorage with jest-environment-jsdom-global
possible?
Documentation of this repo talk about setting the URL at a specific value, can we also talk about what is the work around for
Object.defineProperty(window.location, 'href', {
writable: true
});
Few more examples related to general use cases will be very helpful for folks upgrading to Jest 22 and running into JSDOM 11 issues
There's an updated README that should be made available on the npm
page and package.
Can't take care of this until #2 is taken care of.
This is a bit out of date now:
"peerDependencies": {
"jest-environment-jsdom": "22.x || 23.x || 24.x || 25.x || 26.x"
},
jest-environment-jsdom is up to version 27 now.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.