nwsapi: v2.2.3 DOMException [SyntaxError]: '.disabled):not(:disabled)' is not a valid selector

The following selector was used successfully in v2.2.2 but raises a syntax error v2.2.3:

[data-bs-toggle="dropdown"]:not(.disabled):not(:disabled)

This selector is used by the Bootstrap library:

https://github.com/twbs/bootstrap/blob/3d84e60d690b9755d29f2a8bb9ca807f484768bd/js/src/dropdown.js#L55

Script to reproduce:

const jsdom = require('jsdom');

const dom = new jsdom.JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
dom.window.document.querySelectorAll('[data-bs-toggle="dropdown"]:not(.disabled):not(:disabled)');
$ node test.js

.../node_modules/nwsapi/src/nwsapi.js:559
        throw err;
        ^
DOMException [SyntaxError]: '.disabled):not(:disabled)' is not a valid selector
    at emit (.../node_modules/nwsapi/src/nwsapi.js:557:17)
    at Object._matches [as match] (.../node_modules/nwsapi/src/nwsapi.js:1400:9)
    at Array.Resolver (eval at compile (.../node_modules/nwsapi/src/nwsapi.js:760:17), <anonymous>:3:105)
    at collect (.../node_modules/nwsapi/src/nwsapi.js:1552:21)
    at Object._querySelectorAll [as select] (.../node_modules/nwsapi/src/nwsapi.js:1509:36)
    at DocumentImpl.querySelectorAll (.../node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:78:26)
    at Document.querySelectorAll (.../node_modules/jsdom/lib/jsdom/living/generated/Document.js:1051:58)
    at Object.<anonymous> (.../test.js:4:21)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)

Node.js v18.15.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 26 (6 by maintainers)

Most upvoted comments

I have exactly the same issue. I’m also using Chakra and React testing library. I had to use overrides like this

  "overrides": {
    "nwsapi": "2.2.2"
  },

This resolves the issue but I wonder how this can be resolved permanently.

I also use chraka-ui and 2.2.4 also does not work for me. This is what I get: SyntaxError: ‘:disabled):not([disabled]’ is not a valid selector I get this when running component tests with jest. If I override to 2.2.2, it all works fine.

Confirm the problem with Chakra and React testing library.

We were having the same issue, it is saying that the selector is not valid, rolling back to the 2.2.2 version in the package-lock.json works fine for us.

Screenshot 2023-04-10 at 4 00 10 PM

for yarn

"resolutions": {
    "**/nwsapi": "2.2.2"
  },

I have exactly the same issue. I’m also using Chakra and React testing library. I had to use overrides like this

  "overrides": {
    "nwsapi": "2.2.2"
  },

This resolves the issue but I wonder how this can be resolved permanently.

It helped, thanks. However, I’m looking forward permanent solution.

Also confirming, and for anyone who struggles with it, for overrides to work properly you need npm 8.6.0.

For me 2.2.4 does not work. I use chakra-ui and they use this selector “button:not(:disabled):not([disabled])”. I used “resolutions” in package.json to force 2.2.4. My tests still fail. With 2.2.2 they work.

@jdufresne and all developers in this thread/issue, in commit e60b058 I am trying to fix the :not() pseudo-class bug Could you please test your specific case is fixed by these changes ? In cases where this is not fixed please help by reporting the selector here.

Thank you all for the heads-up, for the suggestions and for the help in solving this bug.

@dperini the fix in your commit appears to be working, though I don’t see it in v2.2.4. Will it be released in v2.2.5 soon?

I have exactly the same issue. I’m also using Chakra and React testing library. I had to use overrides like this

  "overrides": {
    "nwsapi": "2.2.2"
  },

This resolves the issue but I wonder how this can be resolved permanently.

Thanks for the solution, but where should we put this script? Thanks

In the package.json file below the “devDependencies”