- Tags
- Name
- jest
"ReferenceError: document is not defined" in Jest

When you setup Jest, and write down some tests. Sometimes it throws a document is not defined. This means Jest can't get the right environment.
So on your package.json, replace:
{
...
"scripts": {
...
"test": "jest"
...
},
}
With:
{
...
"scripts": {
...
"test": "jest --env=jsdom"
...
},
}
We just solved the ReferenceError: document is not defined
throwed by Jest.