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.

[SOLVED] Error running tests: Cannot read property 'webkitBackingStorePixelRatio' of null

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lavrtoncommented, Oct 18, 2018
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import Konva from 'konva';

Konva.isBrowser = false;

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
  ReactDOM.unmountComponentAtNode(div);
});

2reactions
lavrtoncommented, Oct 18, 2018

Try to do this before all tests Konva.isBrowser = false;. The simple test works ok for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read webkitBackingStorePixelRatio of null ... - GitHub
I'm having difficulty running Konva (via react-konva) with a Mocha test. When using Konva v1.2.2, i got the error: */node_modules/konva/konva.js ...
Read more >
Cannot read property `property` of null in 'react-test-renderer ...
The error originated from one of my component methods, which calls the HTMLElement.focus() method to set focus on a particular input field.
Read more >
Error when running tests while using konva - Stack Overflow
I fixed it by installing and using konva-node in my test: import Konva from 'konva-node';. I also had to specify that it's not...
Read more >
konvajs/konva - Gitter
As the test begins to execute, i am getting the following error: TypeError: Cannot read property 'webkitBackingStorePixelRatio' of null at ...
Read more >
Cannot read properties of null (reading 'contains')error in react ...
TypeError: Cannot read properties of null (reading 'contains'), Need useEffect Cleanup,EventBubblingtypeerror cannot read property of null ...
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