cy.dataCy not inserting double quotes around selector
Hi all,
when using the very useful cy.dataCy selector, it doesn't automatically add double quotes surrounding the data-cy selector, as it is instead clearly stated in the documentation.
This leads to issues when using special characters in the data-cy names, as per my use case when using dots to name different sections of a component.
At the moment I'm working it around by adding the double quotes myself (cy.dataCy('"<selector>"')) but it's kinda annoying to do and ugly to look at.
Thank you
Hi there, I can't really see where that is "clearly stated" in the link you provided
The "data-cy" tip is documented here and I couldn't find anywhere what you're mentioning
You can find here the Cypress reference implementation, which is akin to ours
Up until now we assumed the content in "data-cy" to be a identifier, and not a generic string, basically treating it as a class names
There shouldn't be many problems in supporting arbitrary strings, you can just send a PR updating this line
On the other side, this would be a breaking change for who's relying on the current implementation and added their logic on top of ours helper, e.g. adding double quotes themselves Just take into consideration that we don't plan to release a new major version with breaking changes until Cypress 15 is out and battle tested
Is there any reason why you can't just use dashes or underscores? Or create your own Cypress command? Or override ours in your project to behave as you please?
the example clearly shows the data-cy selector has double quotes around it
even the example you linked shows the same thing
I don't think it would be breaking for anyone, as right now selectors which don't need to be distinguished by double quotes work the same exact way with or whitout them. It would instead be a nice addition to those new to cypress who look at the documentation and assume they can use strings as data-cy selectors, only to find out that with this library they can't
I'm not in the situation to dig into the code of this library and get on par with the team's schedule at the moment, although I agree it should not be that big of a change.
For me, I can add those double quotes myself, I just thought that to make the library as close as cypress' base behavior as possible, the dataCy selector shoul implement those double quotes by itself, that's it
EDIT: typos
I don't think it would be breaking for anyone
If you start adding quotes yourself, then we release a version which adds quotes, your tests will break That's why I said this is a breaking change
This point still stand:
we don't plan to release a new major version with breaking changes until Cypress 15 is out and battle tested
We'll add this feature in the next major version