I'm familiar with the assertion of expect(element).toHaveLength(number)
,
I want to test for a new row addition in a table,
I could just assert some specific item's text to be in the document,
But the situation brought me to think it could be beneficial to be able to get the number of items found by testing-library
's findAllby* queries.
I looked in the testing-library docs for an answer but it seems there is no easy way to check how many items were found by findAllby*...
Any ideas and suggestions will be appreciated
You can assert on the length of findAllBy*
request results like so :
const rows = await findAllByText('my searched text');
expect(rows).toHaveLength(2);
React-testing-library's *All*
queries return arrays : https://testing-library.com/docs/queries/about#types-of-queries