Enzyme: query with an keyword in selector string

Created on 30 Dec 2016  ·  6Comments  ·  Source: enzymejs/enzyme

There is one such keyword in my selector string

const wrapper = mount(<Input/>);
wrapper.find('#link#url')

link#url is an id

when selector string has keyword what should I do ?

Jquery solution is add Escape characters \\ before keyword like link\\#url

bug

All 6 comments

I'm pretty sure "#" is not a valid character in IDs.

“#” for HTML 4 is not a valid character in IDs.

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

but in HTML 5 it's was valid.

The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

It seems very ill-advised to select an ID format that fails hard in older browsers - not very a11y compliant.

That said, I'll leave this open to tackle when we rewrite our selector engine.

In the meantime (and always) you'll be better off using .findWhere and providing a function predicate, instead of relying on strings.

Okay i will try .findWhere

@aweary is this still an issue in v3?

@ljharb it is, #a#b is grammatically ambiguous since the selector spec allows multiple ID selectors. This query will fail even with browser selector parsers, like querySelector (example) so I think it's safe to say this is an unsupported query format.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

heikkimu picture heikkimu  ·  3Comments

nelsonchen90 picture nelsonchen90  ·  3Comments

thurt picture thurt  ·  3Comments

AdamYahid picture AdamYahid  ·  3Comments

ivanbtrujillo picture ivanbtrujillo  ·  3Comments