'React Testing Library : Not able to test hidden buttons
I have an edit button in my application. After clicking the edit button, the Edit button got disappeared and two new buttons were rendered on that place. (Save and Cancel).
I've to test the save and cancel functionality. Tried: const save = await screen.findByTestId('save') After click event is fired.
On Running this getting error that no element is found with save test id.
Solution 1:[1]
Try the below code to wait for the button to appear:
await waitFor(() => screen.findByRole('button', {name:/save/i, hidden: true })
You can also try - await waitFor(() => screen.findAllByRole('button', {name:/save/i, hidden: true })
Check here for more info - React Testing Lib Link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ankit Saxena |
