Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testURL to jest config #1120

Merged
merged 1 commit into from
Dec 5, 2016
Merged

Add testURL to jest config #1120

merged 1 commit into from
Dec 5, 2016

Conversation

spudly
Copy link
Contributor

@spudly spudly commented Nov 30, 2016

In my tests, jsdom was throwing a "SecurityError" at HistoryImpl._sharedPushAndReplaceState (node_modules/react-scripts/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87:15)

This happens because document.URL defaults to "about:blank". Unfortunately, if you interact with the History object it tries and fails to parse the URL, causing a "SecurityError" to be thrown. Setting the default URL to "http://localhost" fixes this issue.

In my tests, jsdom was throwing a "SecurityError" at HistoryImpl._sharedPushAndReplaceState (node_modules/react-scripts/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87:15)

This happens because document.URL defaults to "about:blank". Unfortunately, if you interact with the History object it tries and fails to parse the URL, causing a "SecurityError" to be thrown. Setting the default URL to "http://localhost" fixes this issue.
@gaearon
Copy link
Contributor

gaearon commented Nov 30, 2016

Could you do so in src/setupTests.js instead? I’m not sure if it’s a good default although it looks reasonable.

@spudly
Copy link
Contributor Author

spudly commented Nov 30, 2016

Trying that but having a lot of trouble. Seems there might be a bug in jsdom, but I'm not sure yet.

When I put this in my src/setupTests.js file...

import jsdom from 'react-scripts/node_modules/jsdom';

jsdom.changeURL(window, 'http://localhost'); // Fixes SecurityError exception thrown by jsdom

... I get this error from jsdom:

TypeError: Cannot set property '_URL' of undefined
      at Object.<anonymous>.exports.changeURL (node_modules/react-scripts/node_modules/jsdom/lib/jsdom.js:64:12)
      at Object.<anonymous> (src/setupTests.js:4:43)

The changeURL function is trying to get a document implementation from the window by grabbing window._document[Symbol('impl')] but it is getting undefined, causing the error.

I'll keep trying...

@gaearon gaearon added this to the 0.8.2 milestone Dec 5, 2016
@gaearon
Copy link
Contributor

gaearon commented Dec 5, 2016

It looks reasonable, let's get it in.

@gaearon gaearon merged commit aaa615f into facebook:master Dec 5, 2016
mofelee added a commit to xiaohu-developer/create-react-app that referenced this pull request Dec 7, 2016
* master: (30 commits)
  Relax peerDependencies for ESLint preset (facebook#1191)
  Update Webpack to fix source map issues (facebook#1188)
  Update webpack prod config (facebook#1181)
  Chrome 'open tab' reuse an empty tab when possible (facebook#1165)
  Use file-loader for svgs (facebook#1180)
  Fix Babel issues in tests by applying the right transforms (facebook#1179)
  [babel-preset-react-app] Temporary fix missing babel plugins (facebook#1177)
  Add Subresource Integrity support (facebook#1176)
  Remove path module from webpack config on eject. (facebook#1175)
  Don't strip stack traces of evaluated webpack bundles (facebook#1050)
  Add deploy to Firebase CDN on template's README (Closes facebook#374) (facebook#1143)
  Update e2e.sh (facebook#1167)
  Document what npm build does and pushState (facebook#933)
  Fix minor typo/grammar (facebook#1099)
  Add "npm run build silently fails" to Troubleshooting (facebook#1168)
  Add testURL to jest config (facebook#1120)
  Make jsx-no-undef rule an error (facebook#1159)
  Update CHANGELOG.md
  Publish
  Update changelog for 0.8.1
  ...
@gaearon gaearon mentioned this pull request Dec 7, 2016
@gaearon
Copy link
Contributor

gaearon commented Dec 7, 2016

alexdriaguine pushed a commit to alexdriaguine/create-react-app that referenced this pull request Jan 23, 2017
In my tests, jsdom was throwing a "SecurityError" at HistoryImpl._sharedPushAndReplaceState (node_modules/react-scripts/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87:15)

This happens because document.URL defaults to "about:blank". Unfortunately, if you interact with the History object it tries and fails to parse the URL, causing a "SecurityError" to be thrown. Setting the default URL to "http://localhost" fixes this issue.
randycoulman pushed a commit to CodingZeal/create-react-app that referenced this pull request May 8, 2017
In my tests, jsdom was throwing a "SecurityError" at HistoryImpl._sharedPushAndReplaceState (node_modules/react-scripts/node_modules/jsdom/lib/jsdom/living/window/History-impl.js:87:15)

This happens because document.URL defaults to "about:blank". Unfortunately, if you interact with the History object it tries and fails to parse the URL, causing a "SecurityError" to be thrown. Setting the default URL to "http://localhost" fixes this issue.
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants