Skip to content

Commit

Permalink
Merge pull request #4327 from coralproject/fix/optimize-comment-conta…
Browse files Browse the repository at this point in the history
…iner-tests-again

Optimize CommentContainer.spec.tsx test initialization
  • Loading branch information
tessalt authored Aug 24, 2023
2 parents 18414e9 + 596bd71 commit 0162fd2
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { screen, within } from "@testing-library/react";
import { pureMerge } from "coral-common/utils";
import { screen, waitFor, within } from "@testing-library/react";

import { pureMerge } from "coral-common/utils";
import { GQLResolver } from "coral-framework/schema";
import {
createResolversStub,
Expand Down Expand Up @@ -44,7 +44,19 @@ async function createTestRenderer(

customRenderAppWithContext(context);

const container = await screen.findByTestId("comments-allComments-log");
// it is usually best practice to use findByTestId
// for async work.
//
// source: https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#using-waitfor-to-wait-for-elements-that-can-be-queried-with-find
//
// however, for some special occasions, the test runner
// has a hard time and doing a .getByTestId is more
// performant. Since this cuts the `render username and body`
// test from 1.32s down to 795ms on my machine, I'm doing
// a waitFor + getByTestId here.
const container = await waitFor(() =>
screen.getByTestId("comments-allComments-log")
);

return { container, context };
}
Expand Down

0 comments on commit 0162fd2

Please sign in to comment.