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

Optimize CommentContainer.spec.tsx test initialization #4327

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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