Trying to migrate our tests to Enzyme 3 I seemed to have discovered a regression. A bare child selector, e.g. > a does not work anymore while working fine with v2.
I'm not sure what the preferred format for a test case would be, please let me know.
Thanks for the report @realityking! > a is not a valid selector, so if it was working it was working by mistake. Selectors can't start with combinators. @ljharb are you OK with accepting this as a bug fix? I think changing the grammar to support leading combinators would be tricky.
I think matching the spec is better. In other words, if > a is invalid, then it should never have worked, and we should take the opportunity with the major bump of v3 to shed that baggage.
Sounds good. The formal grammar in the spec states that a selector must start with an actual selector, followed by an optional combinator. You can verify this selector is considered by the browser parser by running document.querySelector('> a')
Sorry for the churn @realityking, but you'll have to update your test logic to avoid selectors with leading combinators. Thanks!
Seems like * > a would work though?
@ljharb that should definitely work, and we do parse it correctly. I just need to implement the behavior https://github.com/airbnb/enzyme/issues/1158
@aweary Thanks. I figured that would be the answer 馃槈 Maybe worthwhile to update the migration documentation?
@ljharb Unfortunately it's not exactly the same. Consider this example:
- div
-- ul
--- li
---- ul
----- li
----- li
--- li
---- ul
----- li
----- li
The selectors > ul > li and * > ul > li would return different results. We actually used a > ul > li selector in testing our menu component.
I had in the back of my mind that querySelectorAll had a similar problem and that I had seen drafts for a solution. Indeed there is :scope in Selectors Level 4 (see https://developer.mozilla.org/en-US/docs/Web/CSS/:scope). Maybe that'd be worth implementing 馃檪