jsdom icon indicating copy to clipboard operation
jsdom copied to clipboard

DOMException.SECURITY_ERR with react router

Open kilianc opened this issue 10 years ago • 4 comments

/../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

kilianc avatar Feb 06 '16 22:02 kilianc

See https://github.com/tmpvar/jsdom/issues/1372.

Sebmaster avatar Feb 06 '16 22:02 Sebmaster

@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

kilianc avatar Feb 06 '16 23:02 kilianc

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 avatar Mar 02 '17 09:03 marlonicus

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

ianlyons avatar Mar 25 '17 00:03 ianlyons