Adding Custom Testing Library Queries
Testing Library is great. But it’s lacking a few queries I would find useful.
Here’s an example of enhancing Cypress Testing Library with a plain function:
I often write tests that target a specific HTML
tag using @TestingLib. So I just created this simple helper function that:
1. Searches for a heading by role and text.
2. Returns thethat heading is in. Now I can easily find a
by heading! 🔥 pic.twitter.com/MglXq8Ymwt — Cory House (@housecor) January 24, 2021
Testing Library supports formally adding custom queries as well, but a simple function like this is straightforward and does the trick.
This technique is inspired by this issue.