If you are using jsdom
(ver 11.12.0) without jest
(e.g. with ava + enzyme
)
then you can set url in jsdom config file
File src/test/jsdom-config.js
const jsdom = require('jsdom') // eslint-disable-line
const { JSDOM } = jsdom
const dom = new JSDOM('<!DOCTYPE html><head/><body></body>', {
url: 'http://localhost/',
referrer: 'https://example.com/',
contentType: 'text/html',
userAgent: 'Mellblomenator/9000',
includeNodeLocations: true,
storageQuota: 10000000,
})
global.window = dom.window
global.document = window.document
global.navigator = window.navigator
AVA settings in package.json
{
...
"scripts": ...
...
"ava": {
"babel": "inherit",
"files": [
"src/**/*.test.js"
],
"verbose": true,
"require": [
"babel-register",
"ignore-styles",
"./src/test/jsdom-setup.js",
"./src/test/enzyme-setup.js"
]
}
}
testURL
was removed in Jest 28, it can now be set viatestEnvironmentOptions.url
injest.config.js
instead (see github.com/jestjs/jest/pull/10797). – Dressy