[SOLVED] Error running tests: Cannot read property 'webkitBackingStorePixelRatio' of null
See original GitHub issueI have a create-react-app project, not ejected, no custom setup.
When I run npm run test
I get the following error:
TypeError: Cannot read property ‘webkitBackingStorePixelRatio’ of null
The only test running is the one included with create-react-app, that is:
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
Test aside, the app renders properly, no warnings or errors in console.
In the error stack in the console I see three distinct blocks, here’s the first two lines for each:
console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Uncaught [TypeError: Cannot read property ‘webkitBackingStorePixelRatio’ of null]
console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Uncaught [TypeError: Cannot read property ‘current’ of undefined]
The error seems related to jsdom limitations, so I also tried to install canvas and canvas-prebuilt as dev-dependencies with no luck.
Any idea on how to solve this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Try to do this before all tests
Konva.isBrowser = false;
. The simple test works ok for me.