I am writing a test for my React application.
I have two dropdowns. Once a selection is made in the first one, a fetch request is trigged and the data from that fetch request is used to populate the second dropdown.
My test looks like this:
test("fruit dropdown becomes enabled when food type fruit is selected", async () => {
await page.select('[data-testid="food"]', "fruit"); // this makes a selection in the drop down and fires a request
// I should wait for request to finish before doing this
const isFruitDropdownDisabled = await page.$eval(
'[data-testid="fruit"]',
element => element.disabled
);
expect(isFruitDropdownDisabled).toBe(false);
}, 16000);
Right now that test fails, how do I tell it to wait until the fetch request has finished before checking if [data-testid="fruit"] is disabled?