diff --git a/package.json b/package.json index ebc247778..2eb8a88eb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/datepicker/__tests__/DateRangePicker.test.tsx b/src/datepicker/__tests__/DateRangePicker.test.tsx index da840a8d4..99f213339 100644 --- a/src/datepicker/__tests__/DateRangePicker.test.tsx +++ b/src/datepicker/__tests__/DateRangePicker.test.tsx @@ -129,11 +129,15 @@ const DateRangePickerComp: React.FC = 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( { expect(screen.getByTestId("segment")).toHaveTextContent( "11/15/2020 - 11/24/2020", ); + + jest.useRealTimers(); }); it("should be invalid on wrong date selection", () => { diff --git a/src/number-input/__tests__/NumberInput.test.tsx b/src/number-input/__tests__/NumberInput.test.tsx index 0e3ed7a9f..6df46b92a 100644 --- a/src/number-input/__tests__/NumberInput.test.tsx +++ b/src/number-input/__tests__/NumberInput.test.tsx @@ -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"; @@ -25,6 +26,7 @@ beforeEach(() => { }); afterEach(() => { + jest.useRealTimers(); cleanup(); (window.requestAnimationFrame as any).mockRestore(); }); @@ -54,7 +56,6 @@ const NumberInputComp = (props: NumberInputProps) => { }; describe("NumberInput", () => { - expect.assertions(1); it("should start with empty string", () => { render(); @@ -146,6 +147,8 @@ describe("NumberInput", () => { }); it("should increase/decrease with scrollwheel", () => { + jest.useFakeTimers(); + render(); const numberInput = screen.getByTestId("numberinput"); @@ -153,12 +156,20 @@ describe("NumberInput", () => { 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"); }); diff --git a/yarn.lock b/yarn.lock index 1fb888387..836d5258f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3993,7 +3993,21 @@ dependencies: defer-to-connect "^2.0.0" -"@testing-library/dom@8.0.0", "@testing-library/dom@^8.0.0": +"@testing-library/dom@8.5.0": + 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==