-
Notifications
You must be signed in to change notification settings - Fork 469
Description
Describe the feature you'd like:
I would like to add a new set of APIs to get/find/query for the nth result. So that would give us getNthByText
, findNthByRole
etc. For example:
await screen.findNthByRole(0, 'button')
This would be similar to doing findAllBy(...)[n]
, but without the awkward (await findAllByRole('button'))[0]
syntax (extra parenthesis needed for the await
).
The API is similar to toHaveBeenNthCalledWith
in Jest.
Additionally, I am working on the Interactions addon for Storybook which provides a GUI for Testing Library:
However, when you do things like getAllByRole('button')[0]
, it's no longer able to track the nested call reference, and it falls back to showing the underlying value (the 0th item in the array):
This can only be avoided by having a dedicated API call, for which the result can then be directly fed into the userEvent method.
I'm totally willing to implement this, no problem.