I've a simple react project created with create-react-app. Just after created the project the yarn test command worked fine, then I started to add some actual react code and I eventually got this error, just after the test is executed:
PASS src/test/App.test.js
✓ renders without crashing (28ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.729s, estimated 1s
Ran all test suites related to changed files.
Watch Usage
› Press a to run all tests.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-scripts/scripts/test.js:20
throw err;
^
TypeError: Cannot read property 'createEvent' of undefined
at Object.invokeGuardedCallbackDev (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:577:25)
at invokeGuardedCallback (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:436:27)
at renderRoot (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:10386:7)
at performWorkOnRoot (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:11000:24)
at performWork (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:10952:7)
at requestWork (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:10861:7)
at scheduleWorkImpl (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:10744:11)
at scheduleWork (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:10706:12)
at Object.enqueueSetState (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react-dom/cjs/react-dom.development.js:6204:7)
at App.Object.<anonymous>.Component.setState (/Users/mpegorar/Development/SpringApps/fluxy_frontend/node_modules/react/cjs/react.development.js:226:16)
at then.then.jsonData (/Users/mpegorar/Development/SpringApps/fluxy_frontend/src/components/App.js:25:9)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The test is actually executed and it changes if I put some error inside, but the tool exit while usually it would stay up and running continuing executing tests based on the code.
The line in my code that seems to cause this error is the set state here described:
componentDidMount() {
const headers = new Headers()
headers.append('Content-Type', 'application/hal+json')
fetch(`${url}/listEnvironmentResources`, { headers }).then(
function(response){
return response.json();
}
).then(jsonData => {
this.setState({environmentRecords: jsonData._embedded.environmentRecordResources});
});
}
Previously the test was not working because of this error, fixed as for the accepted answer.
The only reference I found about the error is this, but it didn't solve my problem.
Any idea how can I fix this? Looks like some missing dependency but can't find which one.