jeudi 11 février 2021

How to wait until button's disabled state is changed in testing library?

I have a React component with a input field and a button disabled at the very beginning. This button's state ( disabled ) changes if input provided by user to input field is validated by API, which is called after anything is typed in input field.

I am testing by providing a valid input but it needs to wait until API's call is completed, so basically i want to test, if on providing a valid input, button get re enabled or not in my test.

I am doing this by following code:

    await waitFor(() => expect(getByTestId("my-btn")).not.toBeDisabled());

But its not working even with a valid input

Aucun commentaire:

Enregistrer un commentaire