Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky unit test for the CMReleasesContainer component #20233

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ describe('CMReleasesContainer', () => {
it('should render the container', async () => {
render();

const informationBox = await screen.findByRole('complementary', { name: 'Releases' });
expect(informationBox).toBeInTheDocument();
await waitFor(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think findBy queries already use a waitFor https://testing-library.com/docs/dom-testing-library/api-async#findby-queries. I think what you end up doing here with an additional waitFor is increase the timeout / retries. But It looks like you can pass waitFor options to the findBy query to do that as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark is right, it'll also fail if it's not in the document. There's probably a different async fetch happening elsewhere that updates the component, you might needed to await something else.

const informationBox = await screen.findByRole('complementary', { name: 'Releases' });
expect(informationBox).toBeInTheDocument();
});

const addToReleaseButton = await screen.findByRole('button', { name: 'Add to release' });
expect(addToReleaseButton).toBeInTheDocument();
Expand Down