nwsapi: Last version is breaking my tests

ReferenceError: document is not defined

at …/…/node_modules/nwsapi/src/nwsapi.js:216:21

And it’s true, that line should use doc. or global.document, but document is really undefined.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 19
  • Comments: 22 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Adding the following to our package json fixed it for us.

 "overrides": {
    "nwsapi": "2.2.13"
  }

Hi! Please be more carefull next time. We only had nwsapi as sub-dependency for js-dom and we had to override like someone else suggested.

Updating to 2.2.15 didn’t solve this issue: https://github.com/thymikee/jest-preset-angular/issues/2883

I also get: ReferenceError: document is not defined while running my Jest (ng) tests with nwsapi version 2.2.14. See issue at https://github.com/thymikee/jest-preset-angular/issues/2883.

The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "jsdom" test environment.

ReferenceError: document is not defined

  at node_modules/nwsapi/src/nwsapi.js:215:21
  at Factory (node_modules/nwsapi/src/nwsapi.js:245:6)
  at initNwsapi (node_modules/jsdom/lib/jsdom/living/helpers/selectors.js:10:10)
  at exports.addNwsapi (node_modules/jsdom/lib/jsdom/living/helpers/selectors.js:38:24)

In case anyone needs this info you can lock your dependency resolutions to the last working version like so (in your package.json):

NPM:

  "overrides": {
    "nwsapi": "2.2.13"
  }

Yarn

  "resolutions": {
    "nwsapi": "2.2.13"
  }

Hi @dperini, thanks for the quick turnaround! The latest version (2.2.16) has fixed the document is not defined error in our Jest tests, but now there’s a different one:

SyntaxError: 'input#1 input[type=checkbox]:checked' is not a valid selector
      889 |
    > 890 |     const [option1] = screen.getAllByRole('checkbox', {
          |                              ^
      at emit (node_modules/nwsapi/src/nwsapi.js:651:17)
      at _querySelectorAll (node_modules/nwsapi/src/nwsapi.js:1646:9)
      at Object._querySelector [as first] (node_modules/nwsapi/src/nwsapi.js:1555:14)
      at HTMLInputElementImpl.querySelector (node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:69:44)
      at HTMLInputElement.querySelector (node_modules/jsdom/lib/jsdom/living/generated/Element.js:1094:58)

@arqex yes the most adequate should have been ‘doc’. However in the hurry-up it was fixed slightly in a different way. The next release will hopefully be like you said, but there are rewrites too.

@maf248 Sure , will call before ! Out of pure sarcasm … are you sure there isn’t a different approach that will let us avoid depending on my time, my humor or my capabilities ? A simple checkbox that defer publishing until all dependencies have agreed and are satisfied.

I can confirm my tests run by downgrading to 2.2.13: npm install nwsapi@2.2.13