Skip to content

Commit

Permalink
test: make assertions async
Browse files Browse the repository at this point in the history
  • Loading branch information
adamborowski committed Jan 17, 2023
1 parent d9ace2b commit 21f00b2
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ export const ClientInMemoryMock: ComponentStory<
ClientInMemoryMock.play = async ({ canvasElement }) => {
expect(screen.getByTestId("spinner")).toBeVisible();
await waitFor(
async () => {
await expect(screen.queryByTestId("spinner")).not.toBeInTheDocument();
},
{ timeout: 10000 }
() => expect(screen.queryByTestId("spinner")).not.toBeInTheDocument(),
{ timeout: 10000 }
);
expect(screen.getAllByTestId("repository-card")).toHaveLength(4);

Expand All @@ -42,14 +40,14 @@ ClientInMemoryMock.play = async ({ canvasElement }) => {
await userEvent.click(screen.getByText("Search"));

// now search button should be disabled and we should wait for results
expect(screen.getByText("Search")).toBeDisabled();
expect(screen.getByTestId("spinner")).toBeVisible();
await waitFor(async () => {
expect(screen.getByText("Search")).toBeDisabled();
expect(screen.getByTestId("spinner")).toBeVisible();
});

await waitFor(
async () => {
await expect(screen.queryByTestId("spinner")).not.toBeInTheDocument();
},
{ timeout: 10000 }
() => expect(screen.queryByTestId("spinner")).not.toBeInTheDocument(),
{ timeout: 10000 }
);

// we should see only two repositories in results
Expand All @@ -63,20 +61,24 @@ ClientInMemoryMock.play = async ({ canvasElement }) => {
await delay(300);
await userEvent.click(screen.getByText("Search"));

// now search button should be disabled and we should wait for results
await waitFor(async () => {
expect(screen.getByText("Search")).toBeDisabled();
expect(screen.getByTestId("spinner")).toBeVisible();
});

await waitFor(
async () => {
await expect(screen.queryByTestId("spinner")).not.toBeInTheDocument();
},
{ timeout: 10000 }
() => expect(screen.queryByTestId("spinner")).not.toBeInTheDocument(),
{ timeout: 10000 }
);

expect(screen.queryAllByTestId("repository-card")).toHaveLength(0);
expect(screen.getByText("No repositories found")).toBeVisible();
};


export const ClientRest: ComponentStory<typeof RepositorySearchPageConnected> =
() => <RepositorySearchPageConnected searchClient={restClient} />;
export const ClientRest: ComponentStory<
typeof RepositorySearchPageConnected
> = () => <RepositorySearchPageConnected searchClient={restClient} />;

export const ClientGraphql: ComponentStory<
typeof RepositorySearchPageConnected
Expand Down

0 comments on commit 21f00b2

Please sign in to comment.