enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.95k stars 2.01k forks source link

Error: Failed to parse `:not` attribute value selector #2268

Open craigkovatch opened 5 years ago

craigkovatch commented 5 years ago

Current behavior

wrapper.find(`[role="option"]`) // works
wrapper.find(`[data-itemvalue="apple"]`) // works
wrapper.find(`[role="option"]:not([data-itemvalue="apple"])`) // Error: Failed to parse selector: [role="option"]:not([data-itemvalue="apple"])

Expected behavior

Expected all three examples to work -- @ljharb comments in https://github.com/airbnb/enzyme/issues/456#issuecomment-455670304 that :not selector was added in #1086 and "should be in all versions of enzyme 3."

Your environment

Jasmine running in Wallaby

API

Version

library version
enzyme 3.9.0
react 16.8.6
react-dom 16.8.6
react-test-renderer 16.8.6
adapter (below) 1.12.1

Adapter

ljharb commented 5 years ago

In this case, you're chaining it. What about:

wrapper.find(`[role="option"]').filter(':not([data-itemvalue="apple"])`)

?

craigkovatch commented 5 years ago

Seems to be broken across the board

wrapper.find(`:not([data-itemvalue:"apple"])`); // Error: Failed to parse selector: :not([data-itemvalue:"apple"])

wrapper.find(`[role="option"]`).filter(`:not([data-itemvalue:"apple"])`); // Error: Failed to parse selector: :not([data-itemvalue:"apple"])
ljharb commented 5 years ago

hmm - what about ':not(["data-itemvalue"="apple"]' or .filter(':not(div)')? if that still doesn't work then i'd call this a bug.

munkacsimark commented 4 years ago

I would need similar selector for my tests. I want to select a not active li element from a nav list. 🙃

My workaround:

wrapper.find('li').filterWhere(element => !element.prop('className').includes('activeClass'))