I was running my test suite for my react-native application with the command jest
.
The tests would fail in the file jest-runtime/build/index.js
on the line
const wrapper = this._environment.runScript(transformedFile.script)[
(_script_transformer || _load_script_transformer()).default.EVAL_RESULT_VARIABLE];
with the error:
TypeError: Cannot read property 'Object.<anonymous>' of null
My version of jest is 21.2.1
.
Anyway, after some googling, I found that someone was running jest --env=jsdom
. I gave that a try and then my test suite started working.
But what does this option mean?
I know that jsdom is an implementation of the DOM and HTML standards.
But how is this useful to jest? How does this change the behaviour of jest such that now the tests pass?
testEnvironment
property? jestjs.io/docs/en/configuration#testenvironment-string. This would change the defaultjsdom
library used. CLI has higher precedence and would override the value and make it work. Jsdom is required, as it is the headless browser used for testing components. – Jonathan Hamel