Skip to content

Commit

Permalink
test(dom): ✅ fix long pending test fix for dom dep
Browse files Browse the repository at this point in the history
  • Loading branch information
navin-moorthy committed Sep 22, 2021
1 parent 5e682c1 commit b1db4f7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"@storybook/builder-webpack5": "^6.3.8",
"@storybook/manager-webpack5": "^6.3.8",
"@storybook/react": "^6.3.8",
"@testing-library/dom": "8.0.0",
"@testing-library/dom": "^8.5.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.0",
"@testing-library/react-hooks": "^7.0.2",
Expand Down
6 changes: 6 additions & 0 deletions src/datepicker/__tests__/DateRangePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ const DateRangePickerComp: React.FC<DateRangePickerInitialState> = props => {
const openDatePicker = () => {
fireEvent.click(screen.getByText(/open/i));

jest.advanceTimersByTime(1);

expect(screen.getByTestId("datepicker-content")).toBeVisible();
};

describe("DateRangePicker", () => {
it("should select date ranges correctly", () => {
jest.useFakeTimers();

render(
<DateRangePickerComp
defaultValue={{
Expand Down Expand Up @@ -178,6 +182,8 @@ describe("DateRangePicker", () => {
expect(screen.getByTestId("segment")).toHaveTextContent(
"11/15/2020 - 11/24/2020",
);

jest.useRealTimers();
});

it("should be invalid on wrong date selection", () => {
Expand Down
21 changes: 16 additions & 5 deletions src/number-input/__tests__/NumberInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
NumberInputDecrementButton,
NumberInputIncrementButton,
} from "../index";
import { act } from "react-dom/test-utils";
import { repeat } from "../../utils/test-utils";
import { NumberInputProps } from "../stories/NumberInputBasic.component";

Expand All @@ -25,6 +26,7 @@ beforeEach(() => {
});

afterEach(() => {
jest.useRealTimers();
cleanup();
(window.requestAnimationFrame as any).mockRestore();
});
Expand Down Expand Up @@ -54,7 +56,6 @@ const NumberInputComp = (props: NumberInputProps) => {
};

describe("NumberInput", () => {
expect.assertions(1);
it("should start with empty string", () => {
render(<NumberInputComp />);

Expand Down Expand Up @@ -146,19 +147,29 @@ describe("NumberInput", () => {
});

it("should increase/decrease with scrollwheel", () => {
jest.useFakeTimers();

render(<NumberInputComp defaultValue={0} />);
const numberInput = screen.getByTestId("numberinput");

press.Tab();
expect(numberInput).toHaveFocus();
expect(numberInput).toHaveValue("0");

fireEvent.wheel(numberInput, { deltaY: -100 });
fireEvent.wheel(numberInput, { deltaY: -100 });
act(() => {
fireEvent.wheel(numberInput, { deltaY: -100 });
});
act(() => {
fireEvent.wheel(numberInput, { deltaY: -100 });
});
expect(numberInput).toHaveValue("2");

fireEvent.wheel(numberInput, { deltaY: 100 });
fireEvent.wheel(numberInput, { deltaY: 100 });
act(() => {
fireEvent.wheel(numberInput, { deltaY: 100 });
});
act(() => {
fireEvent.wheel(numberInput, { deltaY: 100 });
});
expect(numberInput).toHaveValue("0");
});

Expand Down
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3993,7 +3993,21 @@
dependencies:
defer-to-connect "^2.0.0"

"@testing-library/[email protected]", "@testing-library/dom@^8.0.0":
"@testing-library/[email protected]":
version "8.5.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.5.0.tgz#56e31331015f943a68c6ec27e259fdf16c69ab7d"
integrity sha512-O0fmHFaPlqaYCpa/cBL0cvroMridb9vZsMLacgIqrlxj+fd+bGF8UfAgwsLCHRF84KLBafWlm9CuOvxeNTlodw==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/runtime" "^7.12.5"
"@types/aria-query" "^4.2.0"
aria-query "^4.2.2"
chalk "^4.1.0"
dom-accessibility-api "^0.5.6"
lz-string "^1.4.4"
pretty-format "^27.0.2"

"@testing-library/dom@^8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.0.0.tgz#2bb994393c566aae021db86dd263ba06e8b71b38"
integrity sha512-Ym375MTOpfszlagRnTMO+FOfTt6gRrWiDOWmEnWLu9OvwCPOWtK6i5pBHmZ07wUJiQ7wWz0t8+ZBK2wFo2tlew==
Expand Down

0 comments on commit b1db4f7

Please sign in to comment.