Skip to content

Commit

Permalink
Fix test cases running error on queue
Browse files Browse the repository at this point in the history
  • Loading branch information
zourdyzou committed Aug 5, 2022
1 parent 80af0f2 commit bf7e2ff
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
47 changes: 47 additions & 0 deletions src/components/scoreboard/__snapshots__/scoreboard.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Scoreboard test cases Scoreboard renders correctly 1`] = `
<DocumentFragment>
<div
class="wrapperScoreboard"
>
<div
class="parentCounter"
>
000
</div>
<div>
<select
class="selectLevel"
role="select-component"
>
<option
class="optionLevel"
>
beginner
</option>
<option
class="optionLevel"
>
intermediate
</option>
<option
class="optionLevel"
>
expert
</option>
</select>
<button
class="resetButton"
>
🙂
</button>
</div>
<div
class="parentCounter"
>
010
</div>
</div>
</DocumentFragment>
`;
7 changes: 5 additions & 2 deletions src/components/scoreboard/components/level/level.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ describe("Level component test case", function () {
expect(asFragment()).toMatchSnapshot();
});

it("should Select level behaviour", function () {
it("should Select level behaviour", async function () {
const onChange = jest.fn();
const levelData = ["beginner", "intermediate", "expert"];
render(<Level levelData={levelData} onChange={onChange} />);

userEvent.selectOptions(screen.getByRole("select-component"), "intermediate");
await userEvent.selectOptions(screen.getByRole("select-component"), "intermediate");
expect(screen.getByRole("option", { name: "intermediate" })).toBeEnabled();

await Promise.resolve();
expect(onChange).toHaveBeenCalled();
});
});
28 changes: 28 additions & 0 deletions src/components/scoreboard/scoreboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ScoreBoard } from "@components/scoreboard/scoreboard";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";

describe("Scoreboard test cases", () => {
const levels = ["beginner", "intermediate", "expert"];

it("Scoreboard renders correctly", () => {
const { asFragment } = render(
<ScoreBoard time="000" levels={levels} onReset={() => null} mines="010" onChange={() => null} />
);

expect(asFragment()).toMatchSnapshot();
});
it("Scoreboard select level handler check", async () => {
const onChange = jest.fn();

render(<ScoreBoard time="000" levels={levels} onReset={() => null} mines="010" onChange={onChange} />);

await userEvent.selectOptions(screen.getByRole("select-component"), "expert");

expect(screen.getByRole("option", { name: "expert" })).toBeEnabled();

await Promise.resolve();
expect(onChange).toHaveBeenCalled();
});
});

0 comments on commit bf7e2ff

Please sign in to comment.