React tests: Wrap code that causes state updates in `act()` (#2372)

This commit is contained in:
Shati Patel 2023-04-25 15:01:53 +01:00 коммит произвёл GitHub
Родитель 2d68c1c735
Коммит 298176d8f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 37 добавлений и 22 удалений

Просмотреть файл

@ -1,5 +1,10 @@
import * as React from "react";
import { render as reactRender, screen, waitFor } from "@testing-library/react";
import {
act,
render as reactRender,
screen,
waitFor,
} from "@testing-library/react";
import {
VariantAnalysisRepoStatus,
VariantAnalysisScannedRepositoryDownloadStatus,
@ -319,11 +324,13 @@ describe(RepoRow.name, () => {
status: VariantAnalysisRepoStatus.TimedOut,
});
await act(async () => {
await userEvent.click(
screen.getByRole("button", {
expanded: false,
}),
);
});
screen.getByRole("button", {
expanded: true,
@ -342,11 +349,13 @@ describe(RepoRow.name, () => {
interpretedResults: [],
});
await act(async () => {
await userEvent.click(
screen.getByRole("button", {
expanded: false,
}),
);
});
expect(
screen.getByRole("button", {
@ -365,11 +374,13 @@ describe(RepoRow.name, () => {
},
});
await act(async () => {
await userEvent.click(
screen.getByRole("button", {
expanded: false,
}),
);
});
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
t: "requestRepositoryResults",

Просмотреть файл

@ -1,5 +1,5 @@
import * as React from "react";
import { render as reactRender, screen } from "@testing-library/react";
import { act, render as reactRender, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import {
VariantAnalysisRepoStatus,
@ -155,11 +155,15 @@ describe(VariantAnalysisAnalyzedRepos.name, () => {
expect(
screen.queryByText("This is an empty block."),
).not.toBeInTheDocument();
await act(async () => {
await userEvent.click(
screen.getByRole("button", {
name: /octodemo\/hello-world-2/,
}),
);
});
expect(screen.getByText("This is an empty block.")).toBeInTheDocument();
});