Jsdom: DOMException.SECURITY_ERR with react router

Created on 6 Feb 2016  路  4Comments  路  Source: jsdom/jsdom

/../app/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87
        throw new DOMException(DOMException.SECURITY_ERR, `Could not parse url argument "${url}" to ${methodName} ` +
        ^
SecurityError
    at HistoryImpl._sharedPushAndReplaceState (/../app/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87:15)
    at HistoryImpl.replaceState (/../app/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:72:10)
    at History.replaceState (/../app/node_modules/jsdom/lib/jsdom/living/generated/History.js:89:58)
    at getCurrentLocation (/../app/node_modules/history/lib/createBrowserHistory.js:60:39)
    at Object.listen (/../app/node_modules/history/lib/createHistory.js:106:23)
    at Object.listen (/../app/node_modules/history/lib/createDOMHistory.js:31:20)
    at Object.listen (/../app/node_modules/history/lib/createBrowserHistory.js:144:28)
    at Object.listen (/../app/node_modules/history/lib/useBasename.js:78:22)
    at Object.listen (/../app/node_modules/history/lib/useQueries.js:111:22)
    at syncHistory (/../app/node_modules/react-router-redux/lib/index.js:78:11)

ref: https://github.com/rackt/history/issues/224

Most helpful comment

Just in case anyone was led here via the same stack trace I was:

If you're using Jest, don't forget to add a testURL property to your Jest config. This fixed the issue for me 馃憤

All 4 comments

@Sebmaster I confirm this fixes it:

const jsdom = require('jsdom').jsdom

global.document = jsdom('<!doctype html><html><body><div id="app"></div></body></html>', {
  url: 'http://localhost'
})
global.window = document.defaultView
global.navigator = global.window.navigator

Just in case anyone was led here via the same stack trace I was:

If you're using Jest, don't forget to add a testURL property to your Jest config. This fixed the issue for me 馃憤

@marlonicus would you mind updating that to testURL (all-caps URL)? Thanks for this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacekpl picture jacekpl  路  4Comments

cg433n picture cg433n  路  3Comments

philipwalton picture philipwalton  路  4Comments

Progyan1997 picture Progyan1997  路  3Comments

potapovDim picture potapovDim  路  4Comments