You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the CSS selector # needs to be escaped for a characters that are not valid CSS labels. In this case it is trying to run container.querySelector('#activity.username') but that needs to be escaped to container.querySelector('#activity\\.username'). (double slash to escape in javascript, so the actual string would only have one slash) (see MDN docs).
An alternative would be to use the [id='activity.shift'] selector, as that finds the element without escaping:
Thanks for this @ngbrown! If you could please open a PR for this that would be fantastic. Please add a comment above that line pointing to this issue and briefly explaining why it's not simply using the '#' syntax 👍 Thank you so much for catching this! If you'd like, feel free to add a test that reproduces this bug without these changes as well to make sure we never break this in the future. Thanks again!
I had an element that looks like this:
and calling:
getByLabelText('Username')
throws because it won't find the with an id ofactivity.username
. Having a period in theid
is valid HTML.The reason is that on this line:
https://github.com/kentcdodds/dom-testing-library/blob/4bf26d70eda829ca0470c79952f53f5d51ab423b/src/queries.js#L27
the CSS selector
#
needs to be escaped for a characters that are not valid CSS labels. In this case it is trying to runcontainer.querySelector('#activity.username')
but that needs to be escaped tocontainer.querySelector('#activity\\.username')
. (double slash to escape in javascript, so the actual string would only have one slash) (see MDN docs).An alternative would be to use the
[id='activity.shift']
selector, as that finds the element without escaping:So the whole line would be:
The text was updated successfully, but these errors were encountered: