Jest test Cannot read property 'Object.<anonymous>' of null

Viewed 1392
/Users/***/Desktop/projects/***/node_modules/jest-runtime/build/index.js:517
    const wrapper = this._environment.runScript(transformedFile.script)[

Sometimes if i'm run npm test jest given this error.

2 Answers

This happens to me when not shallow rendering a component in a test.

My guess is that it's caused by the rendering of the children components, so I mocked the parent component of the render function and the tests started running fine.

You have a great example of mocking children components here: https://jestjs.io/docs/en/es6-class-mocks

Related