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

Cannot import this inside jest tests #39

Open
evandrocoan opened this issue Apr 17, 2020 · 1 comment
Open

Cannot import this inside jest tests #39

evandrocoan opened this issue Apr 17, 2020 · 1 comment

Comments

@evandrocoan
Copy link

I got this error:

>npx jest
 FAIL  src/reviewer.test.ts (5.44s)
  × renders test site (23ms)

  ● renders test site

    TypeError: Cannot read property 'href' of undefined

       7 |
    >  8 |     const domJSON = require('domjson');
         |                     ^

      at node_modules/domjson/dist/domJSON.js:19:28
      at node_modules/domjson/dist/domJSON.js:7:23
      at Object.<anonymous> (node_modules/domjson/dist/domJSON.js:15:3)
      at Object.<anonymous> (src/reviewer.test.ts:8:21)

If I import require('jsdom-global')() as suggested on #26 (Usage w/ Jsdom: TypeError: Cannot read property 'href' of undefined), jest breaks on my tear down with this:

 FAIL  src/reviewer.test.ts
  ● Test suite failed to run

    TypeError: Illegal invocation

      at removeEventListener (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:131:15)
@evandrocoan
Copy link
Author

evandrocoan commented Apr 17, 2020

The problem lies with JSDOM and its implementation of the DOM Location API, not with this library.

What jest have to fix with his JSDOM implementation? (so I can report back there), related to:

  1. The window parameter has this location attribute jestjs/jest#9833 - The window parameter has this location attribute
  2. document.domain cannot be set and is incorrect if window.location is set jsdom/jsdom#512 - document.domain cannot be set and is incorrect if window.location is set
  3. TypeError: Cannot read property '_location' of null jsdom/jsdom#2121 - TypeError: Cannot read property '_location' of null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant