Enzyme: find with href attribute of full URL is rejected for being complex

Created on 26 Mar 2016  路  8Comments  路  Source: enzymejs/enzyme

I may have missed an explanation in #70 but I expected this selector to work:

.find('a[href='http://example.com/xyz']')

But instead it complains:
TypeError: Enzyme received a complex CSS selector ('a[href='http://example.com/xyz']') that it does not currently support

If I remove the domain name from URL and make it relative, it works:

.find('a[href='/xyz']')

It gives no error and works as expected.

bug

Most helpful comment

Hmm. This is an unfortunate side effect of the shitty CSS parsing we are doing.

An alternative for you right now is to do: .find({ href: url }) instead of the stringified CSS selector.

All 8 comments

Hmm. This is an unfortunate side effect of the shitty CSS parsing we are doing.

An alternative for you right now is to do: .find({ href: url }) instead of the stringified CSS selector.

also experiencing this with a selector as follows:

find('img[src="http://image.com/image.jpg"]')

@lelandrichardson is there a long-term plan for how you guys want to approach CSS selector parsing? Maybe something that returns an AST for selectors?

An update on this?

@stevenmusumeche our CSS parsing is still not great, we're tracking it and hope to implement an actual CSS parser soon. Until then I'd recommend the workaround that @lelandrichardson mentioned:

An alternative for you right now is to do: .find({ href: url }) instead of the stringified CSS selector.

+1

Closed in #1086

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivanbtrujillo picture ivanbtrujillo  路  3Comments

dschinkel picture dschinkel  路  3Comments

aweary picture aweary  路  3Comments

timhonders picture timhonders  路  3Comments

SandroMachado picture SandroMachado  路  3Comments