In case, if you are accessing your application with a http://localhost
prefix, you need to update your jest configuration (in your jest.config.js
) as,
"jest": {
"verbose": true,
"testURL": "http://localhost/"
}
In case you do not already have any jest configuration, just include the configuration in your package.json
. For example:
{
"name": "...",
"description": "...",
...
"jest": {
"verbose": true,
"testURL": "http://localhost/"
}
}
or in jest.config.js
:
module.exports = {
verbose: true,
testURL: "http://localhost/",
...
}
or if you have projects
configured:
module.exports = {
verbose: true,
projects: [{
runner: 'jest-runner',
testURL: "http://localhost/",
// ...
}]
}
for configuration in package.json
, testURL is removed in jest v28. Now you should use testEnvironmentOptions to pass url option like that:
"jest": {
"verbose": true,
"testEnvironmentOptions": {
"url": "http://localhost/"
}
}