Skip to content

Commit 298176d

Browse files
authored
React tests: Wrap code that causes state updates in act() (#2372)
1 parent 2d68c1c commit 298176d

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

extensions/ql-vscode/src/view/variant-analysis/__tests__/RepoRow.spec.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as React from "react";
2-
import { render as reactRender, screen, waitFor } from "@testing-library/react";
2+
import {
3+
act,
4+
render as reactRender,
5+
screen,
6+
waitFor,
7+
} from "@testing-library/react";
38
import {
49
VariantAnalysisRepoStatus,
510
VariantAnalysisScannedRepositoryDownloadStatus,
@@ -319,11 +324,13 @@ describe(RepoRow.name, () => {
319324
status: VariantAnalysisRepoStatus.TimedOut,
320325
});
321326

322-
await userEvent.click(
323-
screen.getByRole("button", {
324-
expanded: false,
325-
}),
326-
);
327+
await act(async () => {
328+
await userEvent.click(
329+
screen.getByRole("button", {
330+
expanded: false,
331+
}),
332+
);
333+
});
327334

328335
screen.getByRole("button", {
329336
expanded: true,
@@ -342,11 +349,13 @@ describe(RepoRow.name, () => {
342349
interpretedResults: [],
343350
});
344351

345-
await userEvent.click(
346-
screen.getByRole("button", {
347-
expanded: false,
348-
}),
349-
);
352+
await act(async () => {
353+
await userEvent.click(
354+
screen.getByRole("button", {
355+
expanded: false,
356+
}),
357+
);
358+
});
350359

351360
expect(
352361
screen.getByRole("button", {
@@ -365,11 +374,13 @@ describe(RepoRow.name, () => {
365374
},
366375
});
367376

368-
await userEvent.click(
369-
screen.getByRole("button", {
370-
expanded: false,
371-
}),
372-
);
377+
await act(async () => {
378+
await userEvent.click(
379+
screen.getByRole("button", {
380+
expanded: false,
381+
}),
382+
);
383+
});
373384

374385
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
375386
t: "requestRepositoryResults",

extensions/ql-vscode/src/view/variant-analysis/__tests__/VariantAnalysisAnalyzedRepos.spec.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { render as reactRender, screen } from "@testing-library/react";
2+
import { act, render as reactRender, screen } from "@testing-library/react";
33
import userEvent from "@testing-library/user-event";
44
import {
55
VariantAnalysisRepoStatus,
@@ -155,11 +155,15 @@ describe(VariantAnalysisAnalyzedRepos.name, () => {
155155
expect(
156156
screen.queryByText("This is an empty block."),
157157
).not.toBeInTheDocument();
158-
await userEvent.click(
159-
screen.getByRole("button", {
160-
name: /octodemo\/hello-world-2/,
161-
}),
162-
);
158+
159+
await act(async () => {
160+
await userEvent.click(
161+
screen.getByRole("button", {
162+
name: /octodemo\/hello-world-2/,
163+
}),
164+
);
165+
});
166+
163167
expect(screen.getByText("This is an empty block.")).toBeInTheDocument();
164168
});
165169

0 commit comments

Comments
 (0)