I've tried to find an element with class --left in it with element.find('a.--left').
This however gives the error Error: Failed to parse selector: a.--left
When I remove the double hyphen in the component and the selector it does work.
That seems like it鈥檚 because you can鈥檛 have a class name that starts with a hyphen - iow, it鈥檚 actually an invalid selector.
Okay, you're right, my bad :)
Although I did come up with a solution: \--left
This however gives me the same error: Error: Failed to parse selector: a.\--left
according to https://jigsaw.w3.org/css-validator/validator this is valid CSS3, so the selector should work right? I did escape it in the find so it looks like this: element.find('a.\\--left')
Any idea why this doesn't work?
Thanks for your help so far :)
I鈥檓 not sure about that validator, but the spec says it鈥檚 not valid: http://www.w3.org/TR/CSS21/syndata.html#characters
(That link is for v2.1 but i don鈥檛 think it changed in css3)
document.querySelector('.--foo') seems to work in Chrome. I'm not exactly sure if its spec compliant (I'm assuming Chrome is), but we could look into allowing leading hyphens.
As for escaped characters, we're aware its an issue and we do want to support it. See https://github.com/airbnb/enzyme/issues/1218.
my apologies for the wrong link, I did not test to see if it works.
Hereby the link to the actual css validator, which proofs that \--left is correct css3.
https://jigsaw.w3.org/css-validator/#validate_by_input
This will be resolved by https://github.com/aweary/rst-selector-parser/pull/11
The reality is that '--' prefix for class names is quite often used for BEM styled naming of modifiers (no namespace notation).
@aweary
Alright, I ran into this today but according to this issue and PRs it's fixed. I'm using [email protected] which should be using [email protected].
I'm getting this error when I try the following variations:
wrapper.find(".--active");
wrapper.find(".\\--active");
Neither seem to work, I get the Failed to parse selector error.
@kamranayub you may need to rm -rf node_modules && npm install to get the update.
Using enzyme 3.6.0 I'm getting the Failed to parse selector: div.hero-slide.\--initialised error
This is how I produce the error:
const divsWithInitialised = heroSlider(props).find('div.hero-slide.\\--initialised');
What version of rst-selector-parser do you have? If it鈥檚 the latest, then please file a new issue.
Guys would the square brackets in a className be valid? Example:
_test-field-secondaryConditions[0].sourceValue
What does document.querySelector do with those?