@testing-library/dom version: 7.21.2getByLabelText("a11y label text");
Identifying an icon
TypeError: Cannot read property 'getAttribute' of null
39 |
40 | test('then the overlay will render', async() => {
> 41 | expect(getByLabelText("a11y label text")).toBeTruthy();
| ^
42 | });
When the container does not have a node with id "c0-dialog-0-6-text"
<svg aria-hidden="true" class="icon icon--close" focusable="false" aria-labelledby="c0-dialog-0-6-text">
<use href="#icon-close"></use>
</svg>
This generates a JS error rather than returning a user friendly test failure. In fact, it should probably just fail the test with no error.
I think an appropriate fix would be just to return an empty string from the getLabelContent function when "label" doesn't exist.
https://github.com/testing-library/dom-testing-library/blob/master/src/queries/label-text.js#L54
cc @delca85. I think this may be related to your changes. What do you think we should do here?
Yes, it is totally dued by my changes.
Like @msendlakowski said, the code looks for a label with the id found in the aria-labelledby attribute in some element.
I think that the code flow should go on in a case like this, because this is maybe an incoherence found in the dom but not directly related to the inserted query and the element labeled by the desired value could still be found.
Maybe check if the element with the desired is is null before calling getLabelContent is what I should have done from the beginning.
If it sounds good to all of you I could work on it later today.
Sounds great!
:tada: This issue has been resolved in version 7.21.4 :tada:
The release is available on:
npm package (@latest dist-tag)Your semantic-release bot :package::rocket:
Most helpful comment
Yes, it is totally dued by my changes.
Like @msendlakowski said, the code looks for a
labelwith theidfound in thearia-labelledbyattribute in some element.I think that the code flow should go on in a case like this, because this is maybe an incoherence found in the dom but not directly related to the inserted query and the element labeled by the desired value could still be found.
Maybe check if the element with the desired is is
nullbefore callinggetLabelContentis what I should have done from the beginning.If it sounds good to all of you I could work on it later today.