liveAnnouncer direct DOM manipulation and issues with react-testing-library #4915
alirezamirian
started this conversation in
General
Replies: 1 comment
-
@LFDanLu has an RFC for some testing utilities, so this seems like a great fit for there (or in our docs until then.) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We faced an issue in some test suites written using react-testing-library, and it seems not like an issue specific to our setup, so sharing it here.
The issue was test cases affecting each other, and after lots of tracing, and debugging, it turned out it was due to liveAnnouncer leaving behind some role="log" elements, with a content that was matching some of our test selectors in the subsequent test cases.
After looking at LiveAnnouncer code, we realized it directly manipulates DOM, for some technical reason:
react-spectrum/packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx
Lines 54 to 59 in 73d8be4
The issue can be worked around, by calling
destroyAnnouncer
in a beforeEach block, (or just finding all role="logs" and removing them), but it's a very obscure issue, and maybe you want to document it or consider changing the live announcer implementation to be react-aware, despite the explained challenges regarding react-dom 18 API differences.Beta Was this translation helpful? Give feedback.
All reactions