From 8e5e0d85803b4096cf69b90a1969477cb91aebcc Mon Sep 17 00:00:00 2001 From: Mikkel Laursen Date: Sat, 11 Jan 2025 22:15:23 -0500 Subject: [PATCH] chore(core): start supporting multiple test frameworks --- packages/core/jest.config.cjs | 3 + packages/core/jest.setup.ts | 3 +- packages/core/package.json | 5 +- packages/core/src/__tests__/NoSsr.tsx | 2 +- .../core/src/__tests__/useAsyncFunction.tsx | 8 +- .../src/__tests__/useDebouncedFunction.tsx | 9 +- packages/core/src/__tests__/useDropzone.tsx | 2 +- .../core/src/__tests__/useElementSize.tsx | 6 +- packages/core/src/__tests__/useEnsuredId.tsx | 2 +- .../core/src/__tests__/useEnsuredState.tsx | 2 +- .../core/src/__tests__/useHtmlClassName.tsx | 2 +- .../core/src/__tests__/useLocalStorage.tsx | 2 +- .../core/src/__tests__/useOrientation.tsx | 2 +- .../core/src/__tests__/useResizeObserver.tsx | 8 +- .../src/__tests__/useThrottledFunction.tsx | 9 +- packages/core/src/__tests__/useToggle.tsx | 2 +- packages/core/src/__tests__/useWindowSize.tsx | 2 +- .../core/src/app-bar/__tests__/AppBar.tsx | 2 +- .../src/app-bar/__tests__/AppBarTitle.tsx | 2 +- .../autocomplete/__tests__/Autocomplete.tsx | 10 +- .../__tests__/AutocompleteChip.tsx | 2 +- .../AutocompleteCircularProgress.tsx | 2 +- .../__tests__/AutocompleteClearButton.tsx | 2 +- packages/core/src/avatar/__tests__/Avatar.tsx | 2 +- packages/core/src/badge/__tests__/Badge.tsx | 2 +- packages/core/src/box/__tests__/Box.tsx | 2 +- .../core/src/button/__tests__/AsyncButton.tsx | 9 +- packages/core/src/button/__tests__/Button.tsx | 2 +- .../src/button/__tests__/ButtonUnstyled.tsx | 2 +- .../src/button/__tests__/TooltippedButton.tsx | 2 +- packages/core/src/card/__tests__/Card.tsx | 2 +- .../core/src/card/__tests__/CardContent.tsx | 2 +- .../core/src/card/__tests__/CardFooter.tsx | 2 +- .../core/src/card/__tests__/CardHeader.tsx | 2 +- .../core/src/card/__tests__/CardSubtitle.tsx | 2 +- .../core/src/card/__tests__/CardTitle.tsx | 2 +- .../core/src/card/__tests__/ClickableCard.tsx | 2 +- packages/core/src/chip/__tests__/Chip.tsx | 8 +- packages/core/src/dialog/__tests__/Dialog.tsx | 7 +- .../src/dialog/__tests__/DialogContent.tsx | 2 +- .../src/dialog/__tests__/DialogFooter.tsx | 2 +- .../src/dialog/__tests__/DialogHeader.tsx | 2 +- .../core/src/dialog/__tests__/DialogTitle.tsx | 2 +- .../core/src/divider/__tests__/Divider.tsx | 2 +- .../src/draggable/__tests__/useDraggable.tsx | 2 +- .../__tests__/ExpansionPanel.tsx | 8 +- .../core/src/files/__tests__/FileInput.tsx | 2 +- .../src/files/__tests__/useFileUpload.tsx | 8 +- .../src/focus/__tests__/useFocusContainer.tsx | 7 +- packages/core/src/form/__tests__/Checkbox.tsx | 2 +- packages/core/src/form/__tests__/Fieldset.tsx | 2 +- packages/core/src/form/__tests__/Label.tsx | 2 +- packages/core/src/form/__tests__/Legend.tsx | 2 +- .../src/form/__tests__/MenuItemCheckbox.tsx | 2 +- .../core/src/form/__tests__/MenuItemRadio.tsx | 2 +- packages/core/src/form/__tests__/Radio.tsx | 2 +- packages/core/src/form/__tests__/Select.tsx | 2 +- packages/core/src/form/__tests__/Switch.tsx | 2 +- packages/core/src/form/__tests__/TextArea.tsx | 9 +- .../core/src/form/__tests__/TextField.tsx | 2 +- .../src/form/__tests__/useCheckboxGroup.tsx | 2 +- .../core/src/form/__tests__/useFormReset.tsx | 2 +- .../core/src/form/__tests__/useRadioGroup.tsx | 2 +- packages/core/src/icon/__tests__/FontIcon.tsx | 2 +- .../core/src/icon/__tests__/IconRotator.tsx | 2 +- .../core/src/icon/__tests__/MaterialIcon.tsx | 2 +- .../src/icon/__tests__/MaterialSymbol.tsx | 2 +- packages/core/src/icon/__tests__/SVGIcon.tsx | 2 +- .../src/icon/__tests__/TextIconSpacing.tsx | 2 +- .../__tests__/UserInteractionModeProvider.tsx | 2 +- .../__tests__/useHigherContrastChildren.tsx | 2 +- .../src/layout/__tests__/LayoutAppBar.tsx | 6 +- .../core/src/layout/__tests__/LayoutNav.tsx | 2 +- .../layout/__tests__/LayoutWindowSplitter.tsx | 2 +- packages/core/src/layout/__tests__/Main.tsx | 2 +- .../layout/__tests__/useExpandableLayout.tsx | 22 +- .../src/layout/__tests__/useLayoutTree.tsx | 2 +- .../layout/__tests__/useResizableLayout.tsx | 7 +- .../layout/__tests__/useTemporaryLayout.tsx | 7 +- packages/core/src/link/__tests__/Link.tsx | 2 +- .../src/link/__tests__/SkipToMainContent.tsx | 2 +- packages/core/src/list/__tests__/List.tsx | 2 +- packages/core/src/list/__tests__/ListItem.tsx | 8 +- .../core/src/list/__tests__/ListItemLink.tsx | 2 +- .../core/src/list/__tests__/ListSubheader.tsx | 2 +- .../__tests__/AppSizeProvider.tsx | 4 +- .../media-queries/__tests__/useMediaQuery.tsx | 3 +- .../core/src/menu/__tests__/DropdownMenu.tsx | 4 +- packages/core/src/menu/__tests__/MenuBar.tsx | 2 +- .../__tests__/MenuItemCircularProgress.tsx | 2 +- .../menu/__tests__/MenuVisibilityProvider.tsx | 2 +- .../src/menu/__tests__/useContextMenu.tsx | 2 +- .../core/src/navigation/__tests__/NavItem.tsx | 2 +- .../navigation/__tests__/NavItemButton.tsx | 7 +- .../src/navigation/__tests__/NavItemLink.tsx | 6 +- .../src/navigation/__tests__/NavSubheader.tsx | 2 +- .../src/navigation/__tests__/Navigation.tsx | 7 +- .../__tests__/useNavigationExpansion.tsx | 2 +- .../core/src/overlay/__tests__/Overlay.tsx | 8 +- .../__tests__/PortalContainerProvider.tsx | 2 +- .../__tests__/useFixedPositioning.tsx | 2 +- .../progress/__tests__/CircularProgress.tsx | 2 +- .../src/progress/__tests__/LinearProgress.tsx | 2 +- .../__tests__/ResponsiveItem.tsx | 2 +- .../__tests__/ResponsiveItemOverlay.tsx | 2 +- .../src/searching/__tests__/useFuzzyMatch.tsx | 2 +- .../__tests__/SegmentedButton.tsx | 2 +- .../__tests__/SegmentedButtonContainer.tsx | 2 +- packages/core/src/sheet/__tests__/Sheet.tsx | 2 +- .../core/src/snackbar/__tests__/Snackbar.tsx | 2 +- .../core/src/snackbar/__tests__/Toast.tsx | 2 +- .../snackbar/__tests__/ToastActionButton.tsx | 7 +- .../snackbar/__tests__/ToastCloseButton.tsx | 7 +- .../src/snackbar/__tests__/ToastContent.tsx | 2 +- .../__tests__/ToastManagerProvider.tsx | 2 +- .../__tests__/CircularProgressSuspense.tsx | 7 +- .../src/suspense/__tests__/NullSuspense.tsx | 2 +- packages/core/src/table/__tests__/Table.tsx | 2 +- .../core/src/table/__tests__/TableBody.tsx | 2 +- .../src/table/__tests__/TableCheckbox.tsx | 2 +- .../src/table/__tests__/TableContainer.tsx | 2 +- .../core/src/table/__tests__/TableRadio.tsx | 2 +- .../core/src/table/__tests__/TableRow.tsx | 2 +- packages/core/src/tabs/__tests__/Tab.tsx | 2 +- packages/core/src/tabs/__tests__/TabList.tsx | 2 +- packages/core/src/tabs/__tests__/useTabs.tsx | 7 +- packages/core/src/test-utils/index.ts | 7 +- .../core/src/test-utils/jest-globals/index.ts | 3 + .../test-utils/jest-globals/match-media.ts | 38 ++++ .../jest-globals/resize-observer.ts | 109 ++++++++++ .../{jest-setup.ts => jest-globals/setup.ts} | 5 +- .../test-utils/{ => jest-globals}/timers.ts | 4 +- packages/core/src/test-utils/matchMedia.ts | 194 ------------------ .../{ => mocks}/IntersectionObserver.ts | 0 .../test-utils/{ => mocks}/ResizeObserver.ts | 81 +------- .../{ => mocks}/__tests__/ResizeObserver.ts | 10 +- .../mocks/match-media-implementation.ts | 110 ++++++++++ .../core/src/test-utils/mocks/match-media.ts | 63 ++++++ .../polyfills/IntersectionObserver.ts | 2 +- .../test-utils/polyfills/ResizeObserver.ts | 2 +- .../src/test-utils/polyfills/matchMedia.ts | 2 +- .../src/test-utils/utils/resize-observer.ts | 47 +++++ .../LocalStorageColorSchemeProvider.tsx | 2 +- .../src/theme/__tests__/ThemeProvider.tsx | 2 +- .../src/theme/__tests__/useCSSVariables.tsx | 2 +- .../theme/__tests__/useColorSchemeMetaTag.tsx | 2 +- .../core/src/tooltip/__tests__/Tooltip.tsx | 2 +- .../__tests__/TooltipHoverModeProvider.tsx | 2 +- .../transition/__tests__/CSSTransition.tsx | 2 +- .../src/transition/__tests__/Collapse.tsx | 2 +- .../src/transition/__tests__/CrossFade.tsx | 2 +- .../transition/__tests__/ScaleTransition.tsx | 2 +- .../__tests__/SkeletonPlaceholder.tsx | 2 +- .../transition/__tests__/useCSSTransition.tsx | 2 +- .../__tests__/useCollapseTransition.tsx | 2 +- .../__tests__/useCrossFadeTransition.tsx | 2 +- .../__tests__/useMaxWidthTransition.tsx | 2 +- .../__tests__/useScaleTransition.tsx | 2 +- .../transition/__tests__/useTransition.tsx | 8 +- packages/core/src/tree/__tests__/Tree.tsx | 8 +- .../core/src/tree/__tests__/TreeGroup.tsx | 2 +- .../src/tree/__tests__/TreeItemExpander.tsx | 2 +- .../core/src/typography/__tests__/SrOnly.tsx | 2 +- .../typography/__tests__/TextContainer.tsx | 2 +- .../src/typography/__tests__/Typography.tsx | 2 +- .../__tests__/WritingDirectionProvider.tsx | 2 +- .../src/utils/__tests__/RenderRecursively.tsx | 2 +- packages/core/tsconfig.json | 7 +- 168 files changed, 578 insertions(+), 590 deletions(-) create mode 100644 packages/core/src/test-utils/jest-globals/index.ts create mode 100644 packages/core/src/test-utils/jest-globals/match-media.ts create mode 100644 packages/core/src/test-utils/jest-globals/resize-observer.ts rename packages/core/src/test-utils/{jest-setup.ts => jest-globals/setup.ts} (69%) rename packages/core/src/test-utils/{ => jest-globals}/timers.ts (86%) delete mode 100644 packages/core/src/test-utils/matchMedia.ts rename packages/core/src/test-utils/{ => mocks}/IntersectionObserver.ts (100%) rename packages/core/src/test-utils/{ => mocks}/ResizeObserver.ts (81%) rename packages/core/src/test-utils/{ => mocks}/__tests__/ResizeObserver.ts (95%) create mode 100644 packages/core/src/test-utils/mocks/match-media-implementation.ts create mode 100644 packages/core/src/test-utils/mocks/match-media.ts create mode 100644 packages/core/src/test-utils/utils/resize-observer.ts diff --git a/packages/core/jest.config.cjs b/packages/core/jest.config.cjs index 511d64094b..224507e15a 100644 --- a/packages/core/jest.config.cjs +++ b/packages/core/jest.config.cjs @@ -30,6 +30,9 @@ const config = { moduleNameMapper: { "\\.scss$": "identity-obj-proxy", "^(\\.{1,2}/.*)\\.js$": "$1", + "^test-utils$": "/src/test-utils/index.ts", + "^test-utils/jest-globals$": + "/src/test-utils/jest-globals/index.ts", }, watchPlugins: [ diff --git a/packages/core/jest.setup.ts b/packages/core/jest.setup.ts index 7ab92f0764..109fc33a70 100644 --- a/packages/core/jest.setup.ts +++ b/packages/core/jest.setup.ts @@ -1,3 +1,2 @@ -import "@testing-library/jest-dom/jest-globals"; +import "./src/test-utils/jest-globals/setup.js"; import "./src/test-utils/polyfills/index.js"; -import "./src/test-utils/jest-setup.js"; diff --git a/packages/core/package.json b/packages/core/package.json index fa4f94a7e7..a3342eb727 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -16,11 +16,8 @@ "require": "./dist/test-utils/polyfills/*", "default": "./dist/test-utils/polyfills/*.js" }, + "./test-utils/jest-globals": "./dist/test-utils/jest-globals/index.js", "./test-utils": "./dist/test-utils/index.js", - "./test-utils/*": { - "require": "./dist/test-utils/*", - "default": "./dist/test-utils/*.js" - }, "./colors": { "sass": "./dist/_colors.scss", "default": "./dist/theme/colors.js" diff --git a/packages/core/src/__tests__/NoSsr.tsx b/packages/core/src/__tests__/NoSsr.tsx index 3e12dc0ed7..e299608336 100644 --- a/packages/core/src/__tests__/NoSsr.tsx +++ b/packages/core/src/__tests__/NoSsr.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; -import { render, screen } from "../test-utils/index.js"; +import { render, screen } from "test-utils"; import { NoSsr } from "../NoSsr.js"; import { SsrProvider, useSsr } from "../SsrProvider.js"; diff --git a/packages/core/src/__tests__/useAsyncFunction.tsx b/packages/core/src/__tests__/useAsyncFunction.tsx index be94dc5d80..1138d9b65a 100644 --- a/packages/core/src/__tests__/useAsyncFunction.tsx +++ b/packages/core/src/__tests__/useAsyncFunction.tsx @@ -1,12 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { type MouseEvent, type ReactElement } from "react"; -import { - act, - rmdRender, - screen, - userEvent, - waitFor, -} from "../test-utils/index.js"; +import { act, rmdRender, screen, userEvent, waitFor } from "test-utils"; import { box } from "../box/styles.js"; import { Button, type ButtonProps } from "../button/Button.js"; diff --git a/packages/core/src/__tests__/useDebouncedFunction.tsx b/packages/core/src/__tests__/useDebouncedFunction.tsx index ec9021dab5..b236ae9ff2 100644 --- a/packages/core/src/__tests__/useDebouncedFunction.tsx +++ b/packages/core/src/__tests__/useDebouncedFunction.tsx @@ -1,13 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { useState } from "react"; -import { - act, - fireEvent, - render, - screen, - userEvent, - waitFor, -} from "../test-utils/index.js"; +import { act, fireEvent, render, screen, userEvent, waitFor } from "test-utils"; import { Button } from "../button/Button.js"; import { TextField } from "../form/TextField.js"; diff --git a/packages/core/src/__tests__/useDropzone.tsx b/packages/core/src/__tests__/useDropzone.tsx index 2dbb2e8d30..8c64c39aee 100644 --- a/packages/core/src/__tests__/useDropzone.tsx +++ b/packages/core/src/__tests__/useDropzone.tsx @@ -1,7 +1,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { cnb } from "cnbuilder"; import { type ReactElement, type ReactNode } from "react"; -import { fireEvent, render, screen } from "../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { useDropzone, type DropzoneOptions } from "../useDropzone.js"; diff --git a/packages/core/src/__tests__/useElementSize.tsx b/packages/core/src/__tests__/useElementSize.tsx index e033b990da..7008670904 100644 --- a/packages/core/src/__tests__/useElementSize.tsx +++ b/packages/core/src/__tests__/useElementSize.tsx @@ -1,12 +1,10 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type MutableRefObject, type ReactElement } from "react"; +import { act, render, screen } from "test-utils"; import { - act, cleanupResizeObserverAfterEach, - render, - screen, setupResizeObserverMock, -} from "../test-utils/index.js"; +} from "test-utils/jest-globals"; import { type ElementSize } from "../types.js"; import { useElementSize, type ElementSizeOptions } from "../useElementSize.js"; diff --git a/packages/core/src/__tests__/useEnsuredId.tsx b/packages/core/src/__tests__/useEnsuredId.tsx index 80f1cfe2e6..06dea9c241 100644 --- a/packages/core/src/__tests__/useEnsuredId.tsx +++ b/packages/core/src/__tests__/useEnsuredId.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; -import { render, screen } from "../test-utils/index.js"; +import { render, screen } from "test-utils"; import { useEnsuredId } from "../useEnsuredId.js"; diff --git a/packages/core/src/__tests__/useEnsuredState.tsx b/packages/core/src/__tests__/useEnsuredState.tsx index 78ee3103ac..66433888fc 100644 --- a/packages/core/src/__tests__/useEnsuredState.tsx +++ b/packages/core/src/__tests__/useEnsuredState.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { type ReactElement } from "react"; -import { fireEvent, render, screen } from "../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { useEnsuredState } from "../useEnsuredState.js"; import { useToggle } from "../useToggle.js"; diff --git a/packages/core/src/__tests__/useHtmlClassName.tsx b/packages/core/src/__tests__/useHtmlClassName.tsx index c1f2722214..bee2506c01 100644 --- a/packages/core/src/__tests__/useHtmlClassName.tsx +++ b/packages/core/src/__tests__/useHtmlClassName.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render } from "../test-utils/index.js"; +import { render } from "test-utils"; import { useHtmlClassName } from "../useHtmlClassName.js"; diff --git a/packages/core/src/__tests__/useLocalStorage.tsx b/packages/core/src/__tests__/useLocalStorage.tsx index b6c723559e..1b245248bb 100644 --- a/packages/core/src/__tests__/useLocalStorage.tsx +++ b/packages/core/src/__tests__/useLocalStorage.tsx @@ -1,7 +1,7 @@ import { afterEach, describe, expect, it } from "@jest/globals"; import lzString from "lz-string"; import { useEffect, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { Button } from "../button/Button.js"; import { SsrProvider } from "../SsrProvider.js"; diff --git a/packages/core/src/__tests__/useOrientation.tsx b/packages/core/src/__tests__/useOrientation.tsx index 36728ca6c9..e17464a384 100644 --- a/packages/core/src/__tests__/useOrientation.tsx +++ b/packages/core/src/__tests__/useOrientation.tsx @@ -1,5 +1,5 @@ import { describe, expect, it, jest } from "@jest/globals"; -import { act, render } from "../test-utils/index.js"; +import { act, render } from "test-utils"; import { useOrientation } from "../useOrientation.js"; diff --git a/packages/core/src/__tests__/useResizeObserver.tsx b/packages/core/src/__tests__/useResizeObserver.tsx index dc274ab011..1fbaf5a718 100644 --- a/packages/core/src/__tests__/useResizeObserver.tsx +++ b/packages/core/src/__tests__/useResizeObserver.tsx @@ -2,13 +2,15 @@ import { describe, expect, it, jest } from "@jest/globals"; import { useEffect, type ReactElement } from "react"; import { act, - cleanupResizeObserverAfterEach, createResizeObserverEntry, render, screen, - setupResizeObserverMock, waitFor, -} from "../test-utils/index.js"; +} from "test-utils"; +import { + cleanupResizeObserverAfterEach, + setupResizeObserverMock, +} from "test-utils/jest-globals"; import { useResizeObserver, diff --git a/packages/core/src/__tests__/useThrottledFunction.tsx b/packages/core/src/__tests__/useThrottledFunction.tsx index 7b0390ffac..7910ef77bb 100644 --- a/packages/core/src/__tests__/useThrottledFunction.tsx +++ b/packages/core/src/__tests__/useThrottledFunction.tsx @@ -5,14 +5,7 @@ import { type MutableRefObject, type ReactElement, } from "react"; -import { - act, - fireEvent, - render, - screen, - userEvent, - waitFor, -} from "../test-utils/index.js"; +import { act, fireEvent, render, screen, userEvent, waitFor } from "test-utils"; import { Button } from "../button/Button.js"; import { TextField } from "../form/TextField.js"; diff --git a/packages/core/src/__tests__/useToggle.tsx b/packages/core/src/__tests__/useToggle.tsx index b0f028b0b8..bf9bb87db1 100644 --- a/packages/core/src/__tests__/useToggle.tsx +++ b/packages/core/src/__tests__/useToggle.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; -import { fireEvent, render, screen } from "../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { useToggle } from "../useToggle.js"; diff --git a/packages/core/src/__tests__/useWindowSize.tsx b/packages/core/src/__tests__/useWindowSize.tsx index f06bc318c3..e23ecd4bc8 100644 --- a/packages/core/src/__tests__/useWindowSize.tsx +++ b/packages/core/src/__tests__/useWindowSize.tsx @@ -1,7 +1,7 @@ import { beforeAll, beforeEach, describe, expect, it } from "@jest/globals"; import { createRef, type MutableRefObject, type ReactElement } from "react"; import { SsrProvider } from "../SsrProvider.js"; -import { act, render, screen, waitFor } from "../test-utils/index.js"; +import { act, render, screen, waitFor } from "test-utils"; import { type ElementSize } from "../types.js"; import { useWindowSize, type WindowSizeOptions } from "../useWindowSize.js"; diff --git a/packages/core/src/app-bar/__tests__/AppBar.tsx b/packages/core/src/app-bar/__tests__/AppBar.tsx index 33c7d80598..74c52a2261 100644 --- a/packages/core/src/app-bar/__tests__/AppBar.tsx +++ b/packages/core/src/app-bar/__tests__/AppBar.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { AppBar } from "../AppBar.js"; import { AppBarTitle } from "../AppBarTitle.js"; import { type AppBarHeight, type AppBarPosition } from "../styles.js"; diff --git a/packages/core/src/app-bar/__tests__/AppBarTitle.tsx b/packages/core/src/app-bar/__tests__/AppBarTitle.tsx index 2ea729096d..1022bbfb2e 100644 --- a/packages/core/src/app-bar/__tests__/AppBarTitle.tsx +++ b/packages/core/src/app-bar/__tests__/AppBarTitle.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { AppBarTitle } from "../AppBarTitle.js"; import { appBarTitle } from "../styles.js"; diff --git a/packages/core/src/autocomplete/__tests__/Autocomplete.tsx b/packages/core/src/autocomplete/__tests__/Autocomplete.tsx index c3a8e42007..0a21ae901a 100644 --- a/packages/core/src/autocomplete/__tests__/Autocomplete.tsx +++ b/packages/core/src/autocomplete/__tests__/Autocomplete.tsx @@ -1,17 +1,11 @@ import { afterAll, beforeAll, describe, expect, it, jest } from "@jest/globals"; import { cnb } from "cnbuilder"; import { act, createRef, type ReactElement, useEffect, useState } from "react"; +import { rmdRender, screen, userEvent, within } from "test-utils"; +import { type RafSpy, testImmediateRaf } from "test-utils/jest-globals"; import { FontIcon } from "../../icon/FontIcon.js"; import { type MenuItemProps } from "../../menu/MenuItem.js"; import { fuzzySearch } from "../../searching/fuzzy.js"; -import { - type RafSpy, - rmdRender, - screen, - testImmediateRaf, - userEvent, - within, -} from "../../test-utils/index.js"; import { SrOnly } from "../../typography/SrOnly.js"; import { Autocomplete } from "../Autocomplete.js"; import { diff --git a/packages/core/src/autocomplete/__tests__/AutocompleteChip.tsx b/packages/core/src/autocomplete/__tests__/AutocompleteChip.tsx index 1d3659f17f..d48a68dbe3 100644 --- a/packages/core/src/autocomplete/__tests__/AutocompleteChip.tsx +++ b/packages/core/src/autocomplete/__tests__/AutocompleteChip.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { AutocompleteChip } from "../AutocompleteChip.js"; describe("AutocompleteChip", () => { diff --git a/packages/core/src/autocomplete/__tests__/AutocompleteCircularProgress.tsx b/packages/core/src/autocomplete/__tests__/AutocompleteCircularProgress.tsx index e1fd8a362e..fdb151ff4d 100644 --- a/packages/core/src/autocomplete/__tests__/AutocompleteCircularProgress.tsx +++ b/packages/core/src/autocomplete/__tests__/AutocompleteCircularProgress.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { AutocompleteCircularProgress } from "../AutocompleteCircularProgress.js"; describe("AutocompleteCircularProgress", () => { diff --git a/packages/core/src/autocomplete/__tests__/AutocompleteClearButton.tsx b/packages/core/src/autocomplete/__tests__/AutocompleteClearButton.tsx index 7538041a9b..b95a6c3d1b 100644 --- a/packages/core/src/autocomplete/__tests__/AutocompleteClearButton.tsx +++ b/packages/core/src/autocomplete/__tests__/AutocompleteClearButton.tsx @@ -1,5 +1,5 @@ import { describe, expect, it, jest } from "@jest/globals"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { AutocompleteClearButton } from "../AutocompleteClearButton.js"; import { type AutocompleteClearButtonProps } from "../types.js"; diff --git a/packages/core/src/avatar/__tests__/Avatar.tsx b/packages/core/src/avatar/__tests__/Avatar.tsx index 570d24b07f..a605af888d 100644 --- a/packages/core/src/avatar/__tests__/Avatar.tsx +++ b/packages/core/src/avatar/__tests__/Avatar.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Avatar } from "../Avatar.js"; import { avatarImage } from "../styles.js"; diff --git a/packages/core/src/badge/__tests__/Badge.tsx b/packages/core/src/badge/__tests__/Badge.tsx index 4f080d9bee..a7f2d2c0af 100644 --- a/packages/core/src/badge/__tests__/Badge.tsx +++ b/packages/core/src/badge/__tests__/Badge.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Badge } from "../Badge.js"; diff --git a/packages/core/src/box/__tests__/Box.tsx b/packages/core/src/box/__tests__/Box.tsx index e87cdf49b4..476695aba4 100644 --- a/packages/core/src/box/__tests__/Box.tsx +++ b/packages/core/src/box/__tests__/Box.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Box, type BoxProps } from "../Box.js"; import { type BoxAlignItems, type BoxJustifyContent } from "../styles.js"; diff --git a/packages/core/src/button/__tests__/AsyncButton.tsx b/packages/core/src/button/__tests__/AsyncButton.tsx index 4fedf4877a..2c9bcfd6d9 100644 --- a/packages/core/src/button/__tests__/AsyncButton.tsx +++ b/packages/core/src/button/__tests__/AsyncButton.tsx @@ -1,14 +1,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; -import { - act, - rmdRender, - screen, - userEvent, - waitFor, - within, -} from "../../test-utils/index.js"; +import { act, rmdRender, screen, userEvent, waitFor, within } from "test-utils"; import { AsyncButton, type AsyncButtonProps } from "../AsyncButton.js"; describe("AsyncButton", () => { diff --git a/packages/core/src/button/__tests__/Button.tsx b/packages/core/src/button/__tests__/Button.tsx index 85f6d756d1..12f17c4a0e 100644 --- a/packages/core/src/button/__tests__/Button.tsx +++ b/packages/core/src/button/__tests__/Button.tsx @@ -2,7 +2,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; import { INTERACTION_CONFIG } from "../../interaction/config.js"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { SrOnly } from "../../typography/SrOnly.js"; import { Button, type ButtonProps } from "../Button.js"; import { diff --git a/packages/core/src/button/__tests__/ButtonUnstyled.tsx b/packages/core/src/button/__tests__/ButtonUnstyled.tsx index 02481ebdc2..b8b50c6617 100644 --- a/packages/core/src/button/__tests__/ButtonUnstyled.tsx +++ b/packages/core/src/button/__tests__/ButtonUnstyled.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { ButtonUnstyled } from "../ButtonUnstyled.js"; import { buttonUnstyled } from "../buttonUnstyledStyles.js"; diff --git a/packages/core/src/button/__tests__/TooltippedButton.tsx b/packages/core/src/button/__tests__/TooltippedButton.tsx index cd09df4710..b2871b9b6f 100644 --- a/packages/core/src/button/__tests__/TooltippedButton.tsx +++ b/packages/core/src/button/__tests__/TooltippedButton.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; -import { render, screen, userEvent } from "../../test-utils/index.js"; +import { render, screen, userEvent } from "test-utils"; import { TooltippedButton, type TooltippedButtonProps, diff --git a/packages/core/src/card/__tests__/Card.tsx b/packages/core/src/card/__tests__/Card.tsx index 3f0adf73ca..c7a5157908 100644 --- a/packages/core/src/card/__tests__/Card.tsx +++ b/packages/core/src/card/__tests__/Card.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Card } from "../Card.js"; diff --git a/packages/core/src/card/__tests__/CardContent.tsx b/packages/core/src/card/__tests__/CardContent.tsx index 3bed198674..b87e52f191 100644 --- a/packages/core/src/card/__tests__/CardContent.tsx +++ b/packages/core/src/card/__tests__/CardContent.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { CardContent } from "../CardContent.js"; diff --git a/packages/core/src/card/__tests__/CardFooter.tsx b/packages/core/src/card/__tests__/CardFooter.tsx index 2de0f3f9b9..402b5e3bf5 100644 --- a/packages/core/src/card/__tests__/CardFooter.tsx +++ b/packages/core/src/card/__tests__/CardFooter.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { CardFooter } from "../CardFooter.js"; diff --git a/packages/core/src/card/__tests__/CardHeader.tsx b/packages/core/src/card/__tests__/CardHeader.tsx index a0ac6c1864..a44289fe31 100644 --- a/packages/core/src/card/__tests__/CardHeader.tsx +++ b/packages/core/src/card/__tests__/CardHeader.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Button } from "../../button/Button.js"; import { CardHeader } from "../CardHeader.js"; diff --git a/packages/core/src/card/__tests__/CardSubtitle.tsx b/packages/core/src/card/__tests__/CardSubtitle.tsx index 209578df2b..c385c33824 100644 --- a/packages/core/src/card/__tests__/CardSubtitle.tsx +++ b/packages/core/src/card/__tests__/CardSubtitle.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { CardSubtitle } from "../CardSubtitle.js"; diff --git a/packages/core/src/card/__tests__/CardTitle.tsx b/packages/core/src/card/__tests__/CardTitle.tsx index 9a1ef08087..ba56bb6c5d 100644 --- a/packages/core/src/card/__tests__/CardTitle.tsx +++ b/packages/core/src/card/__tests__/CardTitle.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { CardTitle } from "../CardTitle.js"; diff --git a/packages/core/src/card/__tests__/ClickableCard.tsx b/packages/core/src/card/__tests__/ClickableCard.tsx index 887eefb0bf..1a60b6c829 100644 --- a/packages/core/src/card/__tests__/ClickableCard.tsx +++ b/packages/core/src/card/__tests__/ClickableCard.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { ClickableCard } from "../ClickableCard.js"; describe("ClickableCard", () => { diff --git a/packages/core/src/chip/__tests__/Chip.tsx b/packages/core/src/chip/__tests__/Chip.tsx index 2980df4e1c..a7cd07e326 100644 --- a/packages/core/src/chip/__tests__/Chip.tsx +++ b/packages/core/src/chip/__tests__/Chip.tsx @@ -1,12 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type ReactElement } from "react"; -import { - fireEvent, - render, - rmdRender, - screen, - userEvent, -} from "../../test-utils/index.js"; +import { fireEvent, render, rmdRender, screen, userEvent } from "test-utils"; import { FontIcon } from "../../icon/FontIcon.js"; import { INTERACTION_CONFIG } from "../../interaction/config.js"; diff --git a/packages/core/src/dialog/__tests__/Dialog.tsx b/packages/core/src/dialog/__tests__/Dialog.tsx index 2715c78e88..76b611d563 100644 --- a/packages/core/src/dialog/__tests__/Dialog.tsx +++ b/packages/core/src/dialog/__tests__/Dialog.tsx @@ -2,12 +2,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type ReactElement } from "react"; import { Button } from "../../button/Button.js"; import { PORTAL_CONTAINER_ID } from "../../portal/PortalContainerProvider.js"; -import { - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent, waitFor } from "test-utils"; import { useToggle } from "../../useToggle.js"; import { isElementVisible } from "../../utils/isElementVisible.js"; import { Dialog, type DialogProps } from "../Dialog.js"; diff --git a/packages/core/src/dialog/__tests__/DialogContent.tsx b/packages/core/src/dialog/__tests__/DialogContent.tsx index 4048c90697..cd88275c4b 100644 --- a/packages/core/src/dialog/__tests__/DialogContent.tsx +++ b/packages/core/src/dialog/__tests__/DialogContent.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { DialogContent } from "../DialogContent.js"; import { dialogContent } from "../styles.js"; diff --git a/packages/core/src/dialog/__tests__/DialogFooter.tsx b/packages/core/src/dialog/__tests__/DialogFooter.tsx index 0cc73a34ed..d33df2dbd0 100644 --- a/packages/core/src/dialog/__tests__/DialogFooter.tsx +++ b/packages/core/src/dialog/__tests__/DialogFooter.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; import { Button } from "../../button/Button.js"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { DialogFooter } from "../DialogFooter.js"; import { dialogFooter, type DialogFooterAlignment } from "../styles.js"; diff --git a/packages/core/src/dialog/__tests__/DialogHeader.tsx b/packages/core/src/dialog/__tests__/DialogHeader.tsx index 37fc674713..83804c9d9c 100644 --- a/packages/core/src/dialog/__tests__/DialogHeader.tsx +++ b/packages/core/src/dialog/__tests__/DialogHeader.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { DialogHeader } from "../DialogHeader.js"; import { dialogHeader } from "../styles.js"; diff --git a/packages/core/src/dialog/__tests__/DialogTitle.tsx b/packages/core/src/dialog/__tests__/DialogTitle.tsx index 72cbffe6bf..b18e1e1c76 100644 --- a/packages/core/src/dialog/__tests__/DialogTitle.tsx +++ b/packages/core/src/dialog/__tests__/DialogTitle.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { DialogTitle } from "../DialogTitle.js"; describe("DialogTitle", () => { diff --git a/packages/core/src/divider/__tests__/Divider.tsx b/packages/core/src/divider/__tests__/Divider.tsx index 01c0cf1572..aed3e6c795 100644 --- a/packages/core/src/divider/__tests__/Divider.tsx +++ b/packages/core/src/divider/__tests__/Divider.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Divider } from "../Divider.js"; import { divider } from "../styles.js"; diff --git a/packages/core/src/draggable/__tests__/useDraggable.tsx b/packages/core/src/draggable/__tests__/useDraggable.tsx index c3e70a25b1..308b858dd2 100644 --- a/packages/core/src/draggable/__tests__/useDraggable.tsx +++ b/packages/core/src/draggable/__tests__/useDraggable.tsx @@ -7,7 +7,7 @@ import { type ReactElement, type Ref, } from "react"; -import { fireEvent, rmdRender, screen } from "../../test-utils/index.js"; +import { fireEvent, rmdRender, screen } from "test-utils"; import { Button } from "../../button/Button.js"; import { WritingDirectionProvider } from "../../typography/WritingDirectionProvider.js"; diff --git a/packages/core/src/expansion-panel/__tests__/ExpansionPanel.tsx b/packages/core/src/expansion-panel/__tests__/ExpansionPanel.tsx index 63c5b91d7d..01256812e6 100644 --- a/packages/core/src/expansion-panel/__tests__/ExpansionPanel.tsx +++ b/packages/core/src/expansion-panel/__tests__/ExpansionPanel.tsx @@ -1,12 +1,6 @@ import { beforeEach, describe, expect, it } from "@jest/globals"; import { createRef, type ReactElement } from "react"; -import { - fireEvent, - render, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { fireEvent, render, screen, userEvent, waitFor } from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { isElementVisible } from "../../utils/isElementVisible.js"; diff --git a/packages/core/src/files/__tests__/FileInput.tsx b/packages/core/src/files/__tests__/FileInput.tsx index 3feac5a8df..d1b855238c 100644 --- a/packages/core/src/files/__tests__/FileInput.tsx +++ b/packages/core/src/files/__tests__/FileInput.tsx @@ -4,7 +4,7 @@ import { type ButtonTheme, type ButtonThemeType, } from "../../button/buttonStyles.js"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { FileInput } from "../FileInput.js"; const PROPS = { diff --git a/packages/core/src/files/__tests__/useFileUpload.tsx b/packages/core/src/files/__tests__/useFileUpload.tsx index 76e289e506..40b0a2180b 100644 --- a/packages/core/src/files/__tests__/useFileUpload.tsx +++ b/packages/core/src/files/__tests__/useFileUpload.tsx @@ -1,12 +1,6 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { useEffect } from "react"; -import { - act, - fireEvent, - render, - screen, - userEvent, -} from "../../test-utils/index.js"; +import { act, fireEvent, render, screen, userEvent } from "test-utils"; import { FileInput } from "../FileInput.js"; import { type FileUploadOptions, useFileUpload } from "../useFileUpload.js"; diff --git a/packages/core/src/focus/__tests__/useFocusContainer.tsx b/packages/core/src/focus/__tests__/useFocusContainer.tsx index 161bb68fdb..6197146e76 100644 --- a/packages/core/src/focus/__tests__/useFocusContainer.tsx +++ b/packages/core/src/focus/__tests__/useFocusContainer.tsx @@ -1,12 +1,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { type ReactElement } from "react"; import { Button } from "../../button/Button.js"; -import { - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent, waitFor } from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { useScaleTransition } from "../../transition/useScaleTransition.js"; import { useToggle } from "../../useToggle.js"; diff --git a/packages/core/src/form/__tests__/Checkbox.tsx b/packages/core/src/form/__tests__/Checkbox.tsx index d9215bf487..e2974e9f48 100644 --- a/packages/core/src/form/__tests__/Checkbox.tsx +++ b/packages/core/src/form/__tests__/Checkbox.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Checkbox } from "../Checkbox.js"; diff --git a/packages/core/src/form/__tests__/Fieldset.tsx b/packages/core/src/form/__tests__/Fieldset.tsx index 4b7485116e..dca57934f2 100644 --- a/packages/core/src/form/__tests__/Fieldset.tsx +++ b/packages/core/src/form/__tests__/Fieldset.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { fieldset, Fieldset } from "../Fieldset.js"; import { Legend } from "../Legend.js"; diff --git a/packages/core/src/form/__tests__/Label.tsx b/packages/core/src/form/__tests__/Label.tsx index 0a40636b36..c0bf7dd428 100644 --- a/packages/core/src/form/__tests__/Label.tsx +++ b/packages/core/src/form/__tests__/Label.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Label } from "../Label.js"; diff --git a/packages/core/src/form/__tests__/Legend.tsx b/packages/core/src/form/__tests__/Legend.tsx index 41cf03c6fb..3f9b4c5906 100644 --- a/packages/core/src/form/__tests__/Legend.tsx +++ b/packages/core/src/form/__tests__/Legend.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Legend } from "../Legend.js"; diff --git a/packages/core/src/form/__tests__/MenuItemCheckbox.tsx b/packages/core/src/form/__tests__/MenuItemCheckbox.tsx index 068fc0041e..2bdbdbafcd 100644 --- a/packages/core/src/form/__tests__/MenuItemCheckbox.tsx +++ b/packages/core/src/form/__tests__/MenuItemCheckbox.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { type MenuItemCheckboxProps } from "../MenuItemInputToggle.js"; import { MenuItemCheckbox } from "../MenuItemCheckbox.js"; diff --git a/packages/core/src/form/__tests__/MenuItemRadio.tsx b/packages/core/src/form/__tests__/MenuItemRadio.tsx index b8b3e5aaf0..bfd2561b82 100644 --- a/packages/core/src/form/__tests__/MenuItemRadio.tsx +++ b/packages/core/src/form/__tests__/MenuItemRadio.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { type MenuItemRadioProps } from "../MenuItemInputToggle.js"; import { MenuItemRadio } from "../MenuItemRadio.js"; diff --git a/packages/core/src/form/__tests__/Radio.tsx b/packages/core/src/form/__tests__/Radio.tsx index 7e48e87edc..2a8648cccc 100644 --- a/packages/core/src/form/__tests__/Radio.tsx +++ b/packages/core/src/form/__tests__/Radio.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Radio } from "../Radio.js"; diff --git a/packages/core/src/form/__tests__/Select.tsx b/packages/core/src/form/__tests__/Select.tsx index 802cca40bb..a772345933 100644 --- a/packages/core/src/form/__tests__/Select.tsx +++ b/packages/core/src/form/__tests__/Select.tsx @@ -12,7 +12,7 @@ import { waitFor, waitForElementToBeRemoved, within, -} from "../../test-utils/index.js"; +} from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { Form } from "../Form.js"; import { OptGroup } from "../OptGroup.js"; diff --git a/packages/core/src/form/__tests__/Switch.tsx b/packages/core/src/form/__tests__/Switch.tsx index 17246626b3..2121b8809a 100644 --- a/packages/core/src/form/__tests__/Switch.tsx +++ b/packages/core/src/form/__tests__/Switch.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; import { CircularProgress } from "../../progress/CircularProgress.js"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { Switch, type SwitchProps } from "../Switch.js"; const labelProps = { diff --git a/packages/core/src/form/__tests__/TextArea.tsx b/packages/core/src/form/__tests__/TextArea.tsx index ca2be535f1..08a737e10e 100644 --- a/packages/core/src/form/__tests__/TextArea.tsx +++ b/packages/core/src/form/__tests__/TextArea.tsx @@ -1,14 +1,11 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, useState } from "react"; -import { FontIcon } from "../../icon/FontIcon.js"; +import { act, render, screen, userEvent } from "test-utils"; import { - act, cleanupResizeObserverAfterEach, - render, - screen, setupResizeObserverMock, - userEvent, -} from "../../test-utils/index.js"; +} from "test-utils/jest-globals"; +import { FontIcon } from "../../icon/FontIcon.js"; import { TextArea, type TextAreaProps } from "../TextArea.js"; describe("TextArea", () => { diff --git a/packages/core/src/form/__tests__/TextField.tsx b/packages/core/src/form/__tests__/TextField.tsx index b207e97730..36bdcedc5b 100644 --- a/packages/core/src/form/__tests__/TextField.tsx +++ b/packages/core/src/form/__tests__/TextField.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { TextField, type TextFieldProps } from "../TextField.js"; describe("TextField", () => { diff --git a/packages/core/src/form/__tests__/useCheckboxGroup.tsx b/packages/core/src/form/__tests__/useCheckboxGroup.tsx index 35d1c90ae2..e841d48130 100644 --- a/packages/core/src/form/__tests__/useCheckboxGroup.tsx +++ b/packages/core/src/form/__tests__/useCheckboxGroup.tsx @@ -2,7 +2,7 @@ /* eslint-disable jest-dom/prefer-checked */ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { Button } from "../../button/Button.js"; import { AppSizeProvider } from "../../media-queries/AppSizeProvider.js"; diff --git a/packages/core/src/form/__tests__/useFormReset.tsx b/packages/core/src/form/__tests__/useFormReset.tsx index e7c084365a..ef49930df5 100644 --- a/packages/core/src/form/__tests__/useFormReset.tsx +++ b/packages/core/src/form/__tests__/useFormReset.tsx @@ -1,7 +1,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { useRef, useState, type ReactElement } from "react"; import { Button } from "../../button/Button.js"; -import { act, rmdRender, screen, userEvent } from "../../test-utils/index.js"; +import { act, rmdRender, screen, userEvent } from "test-utils"; import { useFormReset } from "../useFormReset.js"; interface TestImplementationProps { diff --git a/packages/core/src/form/__tests__/useRadioGroup.tsx b/packages/core/src/form/__tests__/useRadioGroup.tsx index 9074fb5efa..34cb602ccd 100644 --- a/packages/core/src/form/__tests__/useRadioGroup.tsx +++ b/packages/core/src/form/__tests__/useRadioGroup.tsx @@ -1,7 +1,7 @@ /* eslint-disable jest-dom/prefer-to-have-value */ import { describe, expect, it, jest } from "@jest/globals"; import { type ReactElement } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { Button } from "../../button/Button.js"; import { AppSizeProvider } from "../../media-queries/AppSizeProvider.js"; diff --git a/packages/core/src/icon/__tests__/FontIcon.tsx b/packages/core/src/icon/__tests__/FontIcon.tsx index 646e562ccf..d564b1238d 100644 --- a/packages/core/src/icon/__tests__/FontIcon.tsx +++ b/packages/core/src/icon/__tests__/FontIcon.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { FontIcon } from "../FontIcon.js"; diff --git a/packages/core/src/icon/__tests__/IconRotator.tsx b/packages/core/src/icon/__tests__/IconRotator.tsx index caef46632b..0da05ebacd 100644 --- a/packages/core/src/icon/__tests__/IconRotator.tsx +++ b/packages/core/src/icon/__tests__/IconRotator.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { cnb } from "cnbuilder"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { FontIcon } from "../FontIcon.js"; import { IconRotator } from "../IconRotator.js"; diff --git a/packages/core/src/icon/__tests__/MaterialIcon.tsx b/packages/core/src/icon/__tests__/MaterialIcon.tsx index a4a91ed0b8..b33b93777e 100644 --- a/packages/core/src/icon/__tests__/MaterialIcon.tsx +++ b/packages/core/src/icon/__tests__/MaterialIcon.tsx @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it } from "@jest/globals"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { MaterialIcon } from "../MaterialIcon.js"; import { createRef } from "react"; import { MATERIAL_CONFIG } from "../materialConfig.js"; diff --git a/packages/core/src/icon/__tests__/MaterialSymbol.tsx b/packages/core/src/icon/__tests__/MaterialSymbol.tsx index 5662cbc004..fdd260f836 100644 --- a/packages/core/src/icon/__tests__/MaterialSymbol.tsx +++ b/packages/core/src/icon/__tests__/MaterialSymbol.tsx @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { MaterialSymbol } from "../MaterialSymbol.js"; import { MATERIAL_CONFIG } from "../materialConfig.js"; diff --git a/packages/core/src/icon/__tests__/SVGIcon.tsx b/packages/core/src/icon/__tests__/SVGIcon.tsx index e8c1daf1b6..5ca2367ab8 100644 --- a/packages/core/src/icon/__tests__/SVGIcon.tsx +++ b/packages/core/src/icon/__tests__/SVGIcon.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { SVGIcon } from "../SVGIcon.js"; diff --git a/packages/core/src/icon/__tests__/TextIconSpacing.tsx b/packages/core/src/icon/__tests__/TextIconSpacing.tsx index 7e12a2ffea..898c0e1e1b 100644 --- a/packages/core/src/icon/__tests__/TextIconSpacing.tsx +++ b/packages/core/src/icon/__tests__/TextIconSpacing.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { TextIconSpacing } from "../TextIconSpacing.js"; diff --git a/packages/core/src/interaction/__tests__/UserInteractionModeProvider.tsx b/packages/core/src/interaction/__tests__/UserInteractionModeProvider.tsx index bda0deb511..63b7ef45fe 100644 --- a/packages/core/src/interaction/__tests__/UserInteractionModeProvider.tsx +++ b/packages/core/src/interaction/__tests__/UserInteractionModeProvider.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { type ReactElement } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { UserInteractionModeProvider, diff --git a/packages/core/src/interaction/__tests__/useHigherContrastChildren.tsx b/packages/core/src/interaction/__tests__/useHigherContrastChildren.tsx index c8bee29840..b3deae14be 100644 --- a/packages/core/src/interaction/__tests__/useHigherContrastChildren.tsx +++ b/packages/core/src/interaction/__tests__/useHigherContrastChildren.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type FC, type PropsWithChildren } from "react"; -import { render } from "../../test-utils/index.js"; +import { render } from "test-utils"; import { useHigherContrastChildren } from "../useHigherContrastChildren.js"; diff --git a/packages/core/src/layout/__tests__/LayoutAppBar.tsx b/packages/core/src/layout/__tests__/LayoutAppBar.tsx index 16e0612e51..1de584a28a 100644 --- a/packages/core/src/layout/__tests__/LayoutAppBar.tsx +++ b/packages/core/src/layout/__tests__/LayoutAppBar.tsx @@ -1,12 +1,10 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type ReactElement, type Ref } from "react"; +import { act, rmdRender, screen } from "test-utils"; import { - act, cleanupResizeObserverAfterEach, - rmdRender, - screen, setupResizeObserverMock, -} from "../../test-utils/index.js"; +} from "test-utils/jest-globals"; import { LayoutAppBar, type LayoutAppBarProps } from "../LayoutAppBar.js"; import { Main } from "../Main.js"; diff --git a/packages/core/src/layout/__tests__/LayoutNav.tsx b/packages/core/src/layout/__tests__/LayoutNav.tsx index 85129ee441..dcc1c7b05a 100644 --- a/packages/core/src/layout/__tests__/LayoutNav.tsx +++ b/packages/core/src/layout/__tests__/LayoutNav.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { LayoutNav, type LayoutNavProps } from "../LayoutNav.js"; import { layoutNav } from "../layoutNavStyles.js"; diff --git a/packages/core/src/layout/__tests__/LayoutWindowSplitter.tsx b/packages/core/src/layout/__tests__/LayoutWindowSplitter.tsx index 0d9291c12e..ca9be507e5 100644 --- a/packages/core/src/layout/__tests__/LayoutWindowSplitter.tsx +++ b/packages/core/src/layout/__tests__/LayoutWindowSplitter.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type Ref } from "react"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { LayoutWindowSplitter, type LayoutWindowSplitterProps, diff --git a/packages/core/src/layout/__tests__/Main.tsx b/packages/core/src/layout/__tests__/Main.tsx index 9e2f8a313e..d2126f5845 100644 --- a/packages/core/src/layout/__tests__/Main.tsx +++ b/packages/core/src/layout/__tests__/Main.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { rmdRender, screen, userEvent } from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent } from "test-utils"; import { Main } from "../Main.js"; import { main } from "../mainStyles.js"; diff --git a/packages/core/src/layout/__tests__/useExpandableLayout.tsx b/packages/core/src/layout/__tests__/useExpandableLayout.tsx index 46f1c64551..38b8ec110e 100644 --- a/packages/core/src/layout/__tests__/useExpandableLayout.tsx +++ b/packages/core/src/layout/__tests__/useExpandableLayout.tsx @@ -1,24 +1,24 @@ import { beforeEach, describe, expect, it } from "@jest/globals"; import { type ReactNode } from "react"; -import { AppBar } from "../../app-bar/AppBar.js"; -import { AppBarTitle } from "../../app-bar/AppBarTitle.js"; -import { Button } from "../../button/Button.js"; -import { Form } from "../../form/Form.js"; -import { Radio } from "../../form/Radio.js"; -import { useRadioGroup } from "../../form/useRadioGroup.js"; -import { useAppSize } from "../../media-queries/AppSizeProvider.js"; -import { Sheet } from "../../sheet/Sheet.js"; import { matchDesktop, matchPhone, + matchTablet, rmdRender, screen, - spyOnMatchMedia, userEvent, waitFor, within, -} from "../../test-utils/index.js"; -import { matchTablet } from "../../test-utils/matchMedia.js"; +} from "test-utils"; +import { spyOnMatchMedia } from "test-utils/jest-globals"; +import { AppBar } from "../../app-bar/AppBar.js"; +import { AppBarTitle } from "../../app-bar/AppBarTitle.js"; +import { Button } from "../../button/Button.js"; +import { Form } from "../../form/Form.js"; +import { Radio } from "../../form/Radio.js"; +import { useRadioGroup } from "../../form/useRadioGroup.js"; +import { useAppSize } from "../../media-queries/AppSizeProvider.js"; +import { Sheet } from "../../sheet/Sheet.js"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { isElementVisible } from "../../utils/isElementVisible.js"; import { LayoutNav } from "../LayoutNav.js"; diff --git a/packages/core/src/layout/__tests__/useLayoutTree.tsx b/packages/core/src/layout/__tests__/useLayoutTree.tsx index eb0f6bb912..d1276652fc 100644 --- a/packages/core/src/layout/__tests__/useLayoutTree.tsx +++ b/packages/core/src/layout/__tests__/useLayoutTree.tsx @@ -10,7 +10,7 @@ import { } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; -import { rmdRender, screen, userEvent } from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent } from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { Tree } from "../../tree/Tree.js"; import { type TreeData } from "../../tree/types.js"; diff --git a/packages/core/src/layout/__tests__/useResizableLayout.tsx b/packages/core/src/layout/__tests__/useResizableLayout.tsx index 4dfcf53c7a..c114b2973d 100644 --- a/packages/core/src/layout/__tests__/useResizableLayout.tsx +++ b/packages/core/src/layout/__tests__/useResizableLayout.tsx @@ -16,12 +16,7 @@ import { useRadioGroup } from "../../form/useRadioGroup.js"; import { useAppSize } from "../../media-queries/AppSizeProvider.js"; import { Sheet } from "../../sheet/Sheet.js"; import { drag } from "../../test-utils/drag.js"; -import { - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent, waitFor } from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { removeItemFromStorage } from "../../useLocalStorage.js"; import { isElementVisible } from "../../utils/isElementVisible.js"; diff --git a/packages/core/src/layout/__tests__/useTemporaryLayout.tsx b/packages/core/src/layout/__tests__/useTemporaryLayout.tsx index ee2151d18a..4079779db8 100644 --- a/packages/core/src/layout/__tests__/useTemporaryLayout.tsx +++ b/packages/core/src/layout/__tests__/useTemporaryLayout.tsx @@ -7,12 +7,7 @@ import { Form } from "../../form/Form.js"; import { Radio } from "../../form/Radio.js"; import { useRadioGroup } from "../../form/useRadioGroup.js"; import { Sheet } from "../../sheet/Sheet.js"; -import { - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent, waitFor } from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { Main } from "../Main.js"; import { diff --git a/packages/core/src/link/__tests__/Link.tsx b/packages/core/src/link/__tests__/Link.tsx index 309392f945..29c85efc81 100644 --- a/packages/core/src/link/__tests__/Link.tsx +++ b/packages/core/src/link/__tests__/Link.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Link } from "../Link.js"; diff --git a/packages/core/src/link/__tests__/SkipToMainContent.tsx b/packages/core/src/link/__tests__/SkipToMainContent.tsx index a35c17e664..d3a862c151 100644 --- a/packages/core/src/link/__tests__/SkipToMainContent.tsx +++ b/packages/core/src/link/__tests__/SkipToMainContent.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type FC, type ReactNode } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { SkipToMainContent } from "../SkipToMainContent.js"; diff --git a/packages/core/src/list/__tests__/List.tsx b/packages/core/src/list/__tests__/List.tsx index 44dce217c6..8b9b0cbc6a 100644 --- a/packages/core/src/list/__tests__/List.tsx +++ b/packages/core/src/list/__tests__/List.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { type PropsWithRef } from "../../types.js"; import { List, type ListElement, type ListProps } from "../List.js"; diff --git a/packages/core/src/list/__tests__/ListItem.tsx b/packages/core/src/list/__tests__/ListItem.tsx index 5ca6acab19..d07ad0ade4 100644 --- a/packages/core/src/list/__tests__/ListItem.tsx +++ b/packages/core/src/list/__tests__/ListItem.tsx @@ -1,12 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type ReactElement, type Ref } from "react"; -import { - fireEvent, - render, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { fireEvent, render, screen, userEvent, waitFor } from "test-utils"; import { UserInteractionModeProvider } from "../../interaction/UserInteractionModeProvider.js"; import { INTERACTION_CONFIG } from "../../interaction/config.js"; diff --git a/packages/core/src/list/__tests__/ListItemLink.tsx b/packages/core/src/list/__tests__/ListItemLink.tsx index 10142b0148..6302f30de2 100644 --- a/packages/core/src/list/__tests__/ListItemLink.tsx +++ b/packages/core/src/list/__tests__/ListItemLink.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { forwardRef, type HTMLAttributes, type ReactElement } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Link } from "../../link/Link.js"; import { List } from "../List.js"; diff --git a/packages/core/src/list/__tests__/ListSubheader.tsx b/packages/core/src/list/__tests__/ListSubheader.tsx index 86990c275e..5925646360 100644 --- a/packages/core/src/list/__tests__/ListSubheader.tsx +++ b/packages/core/src/list/__tests__/ListSubheader.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type ReactElement, type Ref } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { List } from "../List.js"; import { ListSubheader, type ListSubheaderProps } from "../ListSubheader.js"; diff --git a/packages/core/src/media-queries/__tests__/AppSizeProvider.tsx b/packages/core/src/media-queries/__tests__/AppSizeProvider.tsx index 98bec0f58a..637db9a13d 100644 --- a/packages/core/src/media-queries/__tests__/AppSizeProvider.tsx +++ b/packages/core/src/media-queries/__tests__/AppSizeProvider.tsx @@ -5,8 +5,8 @@ import { matchPhone, matchTablet, render, - spyOnMatchMedia, -} from "../../test-utils/index.js"; +} from "test-utils"; +import { spyOnMatchMedia } from "test-utils/jest-globals"; import { type AppSize } from "../appSize.js"; import { AppSizeProvider, useAppSize } from "../AppSizeProvider.js"; diff --git a/packages/core/src/media-queries/__tests__/useMediaQuery.tsx b/packages/core/src/media-queries/__tests__/useMediaQuery.tsx index 1ffe21c630..6b6a452a91 100644 --- a/packages/core/src/media-queries/__tests__/useMediaQuery.tsx +++ b/packages/core/src/media-queries/__tests__/useMediaQuery.tsx @@ -1,5 +1,6 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; -import { matchPhone, render, spyOnMatchMedia } from "../../test-utils/index.js"; +import { matchPhone, render } from "test-utils"; +import { spyOnMatchMedia } from "test-utils/jest-globals"; import { DEFAULT_DESKTOP_MIN_WIDTH } from "../appSize.js"; import { useMediaQuery } from "../useMediaQuery.js"; diff --git a/packages/core/src/menu/__tests__/DropdownMenu.tsx b/packages/core/src/menu/__tests__/DropdownMenu.tsx index 04895372d0..3fede85890 100644 --- a/packages/core/src/menu/__tests__/DropdownMenu.tsx +++ b/packages/core/src/menu/__tests__/DropdownMenu.tsx @@ -4,12 +4,12 @@ import { act, rmdRender, screen, - testImmediateRaf, userEvent, waitFor, waitForElementToBeRemoved, within, -} from "../../test-utils/index.js"; +} from "test-utils"; +import { testImmediateRaf } from "test-utils/jest-globals"; import { Button } from "../../button/Button.js"; import { DialogFooter } from "../../dialog/DialogFooter.js"; diff --git a/packages/core/src/menu/__tests__/MenuBar.tsx b/packages/core/src/menu/__tests__/MenuBar.tsx index bbe4da0243..adb58fffc1 100644 --- a/packages/core/src/menu/__tests__/MenuBar.tsx +++ b/packages/core/src/menu/__tests__/MenuBar.tsx @@ -8,7 +8,7 @@ import { userEvent, waitFor, within, -} from "../../test-utils/index.js"; +} from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { DropdownMenu } from "../DropdownMenu.js"; diff --git a/packages/core/src/menu/__tests__/MenuItemCircularProgress.tsx b/packages/core/src/menu/__tests__/MenuItemCircularProgress.tsx index d10f1b0c49..b34f8cd986 100644 --- a/packages/core/src/menu/__tests__/MenuItemCircularProgress.tsx +++ b/packages/core/src/menu/__tests__/MenuItemCircularProgress.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type ReactElement } from "react"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { MenuItemCircularProgress } from "../MenuItemCircularProgress.js"; function render(ui: ReactElement) { diff --git a/packages/core/src/menu/__tests__/MenuVisibilityProvider.tsx b/packages/core/src/menu/__tests__/MenuVisibilityProvider.tsx index 05894e31c5..12facc2644 100644 --- a/packages/core/src/menu/__tests__/MenuVisibilityProvider.tsx +++ b/packages/core/src/menu/__tests__/MenuVisibilityProvider.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { Button } from "../../button/Button.js"; import { useMenuVisibility } from "../MenuVisibilityProvider.js"; diff --git a/packages/core/src/menu/__tests__/useContextMenu.tsx b/packages/core/src/menu/__tests__/useContextMenu.tsx index 965411c177..54d2e837fb 100644 --- a/packages/core/src/menu/__tests__/useContextMenu.tsx +++ b/packages/core/src/menu/__tests__/useContextMenu.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; -import { fireEvent, rmdRender, screen } from "../../test-utils/index.js"; +import { fireEvent, rmdRender, screen } from "test-utils"; import { Menu } from "../Menu.js"; import { MenuItem } from "../MenuItem.js"; import { useContextMenu } from "../useContextMenu.js"; diff --git a/packages/core/src/navigation/__tests__/NavItem.tsx b/packages/core/src/navigation/__tests__/NavItem.tsx index b95265b76b..3ef38844bf 100644 --- a/packages/core/src/navigation/__tests__/NavItem.tsx +++ b/packages/core/src/navigation/__tests__/NavItem.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { NavItem } from "../NavItem.js"; describe("NavItem", () => { diff --git a/packages/core/src/navigation/__tests__/NavItemButton.tsx b/packages/core/src/navigation/__tests__/NavItemButton.tsx index dac1ce281b..6a4b34d91e 100644 --- a/packages/core/src/navigation/__tests__/NavItemButton.tsx +++ b/packages/core/src/navigation/__tests__/NavItemButton.tsx @@ -1,12 +1,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type ReactElement, type Ref } from "react"; import { type IconRotatorBaseProps } from "../../icon/IconRotator.js"; -import { - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent, waitFor } from "test-utils"; import { useToggle } from "../../useToggle.js"; import { NavItemButton, type NavItemButtonProps } from "../NavItemButton.js"; diff --git a/packages/core/src/navigation/__tests__/NavItemLink.tsx b/packages/core/src/navigation/__tests__/NavItemLink.tsx index 253ce5dda7..ef256f4ae7 100644 --- a/packages/core/src/navigation/__tests__/NavItemLink.tsx +++ b/packages/core/src/navigation/__tests__/NavItemLink.tsx @@ -7,7 +7,7 @@ import { userEvent, waitFor, waitForElementToBeRemoved, -} from "../../test-utils/index.js"; +} from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { useToggle } from "../../useToggle.js"; import { CollapsibleNavGroup } from "../CollapsibleNavGroup.js"; @@ -83,7 +83,9 @@ describe("NavItemLink", () => { name: "Home", }); - expect(tooltip).toHaveStyle("position: fixed; left: 24px;top: 16px;"); + await waitFor(() => { + expect(tooltip).toHaveStyle("position: fixed; left: 24px; top: 16px;"); + }); expect(tooltip).toMatchSnapshot(); }); diff --git a/packages/core/src/navigation/__tests__/NavSubheader.tsx b/packages/core/src/navigation/__tests__/NavSubheader.tsx index 3778684bec..af864e9fb2 100644 --- a/packages/core/src/navigation/__tests__/NavSubheader.tsx +++ b/packages/core/src/navigation/__tests__/NavSubheader.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { NavSubheader } from "../NavSubheader.js"; describe("NavSubheader", () => { diff --git a/packages/core/src/navigation/__tests__/Navigation.tsx b/packages/core/src/navigation/__tests__/Navigation.tsx index 65f18984f0..d3caa23b67 100644 --- a/packages/core/src/navigation/__tests__/Navigation.tsx +++ b/packages/core/src/navigation/__tests__/Navigation.tsx @@ -1,12 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; -import { - render as baseRender, - screen, - userEvent, - within, -} from "../../test-utils/index.js"; +import { render as baseRender, screen, userEvent, within } from "test-utils"; import { Navigation, type NavigationProps } from "../Navigation.js"; import { type NavigationItem } from "../types.js"; import { useNavigationExpansion } from "../useNavigationExpansion.js"; diff --git a/packages/core/src/navigation/__tests__/useNavigationExpansion.tsx b/packages/core/src/navigation/__tests__/useNavigationExpansion.tsx index 0a386b243b..80f8d28868 100644 --- a/packages/core/src/navigation/__tests__/useNavigationExpansion.tsx +++ b/packages/core/src/navigation/__tests__/useNavigationExpansion.tsx @@ -8,7 +8,7 @@ import { } from "react"; import { Button } from "../../button/Button.js"; import { FontIcon } from "../../icon/FontIcon.js"; -import { render, screen, userEvent } from "../../test-utils/index.js"; +import { render, screen, userEvent } from "test-utils"; import { type UseStateInitializer } from "../../types.js"; import { Navigation } from "../Navigation.js"; import { type NavigationItem } from "../types.js"; diff --git a/packages/core/src/overlay/__tests__/Overlay.tsx b/packages/core/src/overlay/__tests__/Overlay.tsx index 1a757836fa..df340998b5 100644 --- a/packages/core/src/overlay/__tests__/Overlay.tsx +++ b/packages/core/src/overlay/__tests__/Overlay.tsx @@ -1,12 +1,6 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import { createRef, type ReactElement } from "react"; -import { - fireEvent, - render, - screen, - waitFor, - within, -} from "../../test-utils/index.js"; +import { fireEvent, render, screen, waitFor, within } from "test-utils"; import { SsrProvider } from "../../SsrProvider.js"; import { Button } from "../../button/Button.js"; diff --git a/packages/core/src/portal/__tests__/PortalContainerProvider.tsx b/packages/core/src/portal/__tests__/PortalContainerProvider.tsx index bf67945bed..0f06ffbc01 100644 --- a/packages/core/src/portal/__tests__/PortalContainerProvider.tsx +++ b/packages/core/src/portal/__tests__/PortalContainerProvider.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { useRef, type ReactElement } from "react"; import { Portal } from "../Portal.js"; diff --git a/packages/core/src/positioning/__tests__/useFixedPositioning.tsx b/packages/core/src/positioning/__tests__/useFixedPositioning.tsx index f1ad9635b2..7b07adee1d 100644 --- a/packages/core/src/positioning/__tests__/useFixedPositioning.tsx +++ b/packages/core/src/positioning/__tests__/useFixedPositioning.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useRef, useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { TRANSITION_CONFIG } from "../../transition/config.js"; import { useScaleTransition } from "../../transition/useScaleTransition.js"; diff --git a/packages/core/src/progress/__tests__/CircularProgress.tsx b/packages/core/src/progress/__tests__/CircularProgress.tsx index 08d3b24dae..7516fd0c17 100644 --- a/packages/core/src/progress/__tests__/CircularProgress.tsx +++ b/packages/core/src/progress/__tests__/CircularProgress.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { CircularProgress } from "../CircularProgress.js"; diff --git a/packages/core/src/progress/__tests__/LinearProgress.tsx b/packages/core/src/progress/__tests__/LinearProgress.tsx index cebba5f479..e97152313b 100644 --- a/packages/core/src/progress/__tests__/LinearProgress.tsx +++ b/packages/core/src/progress/__tests__/LinearProgress.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { LinearProgress } from "../LinearProgress.js"; diff --git a/packages/core/src/responsive-item/__tests__/ResponsiveItem.tsx b/packages/core/src/responsive-item/__tests__/ResponsiveItem.tsx index a5a9ffeb06..676e0eda66 100644 --- a/packages/core/src/responsive-item/__tests__/ResponsiveItem.tsx +++ b/packages/core/src/responsive-item/__tests__/ResponsiveItem.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render } from "../../test-utils/index.js"; +import { render } from "test-utils"; import { type PropsWithRef } from "../../types.js"; import { ResponsiveItem, type ResponsiveItemProps } from "../ResponsiveItem.js"; diff --git a/packages/core/src/responsive-item/__tests__/ResponsiveItemOverlay.tsx b/packages/core/src/responsive-item/__tests__/ResponsiveItemOverlay.tsx index 6ca4037f00..2fb89ef015 100644 --- a/packages/core/src/responsive-item/__tests__/ResponsiveItemOverlay.tsx +++ b/packages/core/src/responsive-item/__tests__/ResponsiveItemOverlay.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render } from "../../test-utils/index.js"; +import { render } from "test-utils"; import { type PropsWithRef } from "../../types.js"; import { Typography } from "../../typography/Typography.js"; import { diff --git a/packages/core/src/searching/__tests__/useFuzzyMatch.tsx b/packages/core/src/searching/__tests__/useFuzzyMatch.tsx index 8d603634cf..e963fdb13e 100644 --- a/packages/core/src/searching/__tests__/useFuzzyMatch.tsx +++ b/packages/core/src/searching/__tests__/useFuzzyMatch.tsx @@ -1,7 +1,7 @@ import { describe, expect, it, jest } from "@jest/globals"; import { nanoid } from "nanoid"; import { useState } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { type NonNullMutableRef } from "../../types.js"; import { createFuzzyRegExp } from "../fuzzy.js"; import { toSearchQuery } from "../toSearchQuery.js"; diff --git a/packages/core/src/segmented-button/__tests__/SegmentedButton.tsx b/packages/core/src/segmented-button/__tests__/SegmentedButton.tsx index f0b1fd6d01..1682ddfa5e 100644 --- a/packages/core/src/segmented-button/__tests__/SegmentedButton.tsx +++ b/packages/core/src/segmented-button/__tests__/SegmentedButton.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; import { FontIcon } from "../../icon/FontIcon.js"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { SegmentedButton } from "../SegmentedButton.js"; import { segmentedButton } from "../segmentedButtonStyles.js"; diff --git a/packages/core/src/segmented-button/__tests__/SegmentedButtonContainer.tsx b/packages/core/src/segmented-button/__tests__/SegmentedButtonContainer.tsx index fb1e2c07cc..b0179ad723 100644 --- a/packages/core/src/segmented-button/__tests__/SegmentedButtonContainer.tsx +++ b/packages/core/src/segmented-button/__tests__/SegmentedButtonContainer.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { SegmentedButtonContainer } from "../SegmentedButtonContainer.js"; import { segmentedButtonContainerStyles } from "../segmentedButtonContainerStyles.js"; diff --git a/packages/core/src/sheet/__tests__/Sheet.tsx b/packages/core/src/sheet/__tests__/Sheet.tsx index 3a38373365..2ad7b364b9 100644 --- a/packages/core/src/sheet/__tests__/Sheet.tsx +++ b/packages/core/src/sheet/__tests__/Sheet.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type ReactElement } from "react"; import { Button } from "../../button/Button.js"; -import { rmdRender, screen } from "../../test-utils/index.js"; +import { rmdRender, screen } from "test-utils"; import { useToggle } from "../../useToggle.js"; import { type BaseSheetProps, Sheet } from "../Sheet.js"; diff --git a/packages/core/src/snackbar/__tests__/Snackbar.tsx b/packages/core/src/snackbar/__tests__/Snackbar.tsx index 4dac46ed73..2fe3f5821e 100644 --- a/packages/core/src/snackbar/__tests__/Snackbar.tsx +++ b/packages/core/src/snackbar/__tests__/Snackbar.tsx @@ -5,7 +5,7 @@ import { screen, type ReactMDRenderOptions, type RenderResult, -} from "../../test-utils/index.js"; +} from "test-utils"; import { Snackbar } from "../Snackbar.js"; import { ToastManager } from "../ToastManager.js"; diff --git a/packages/core/src/snackbar/__tests__/Toast.tsx b/packages/core/src/snackbar/__tests__/Toast.tsx index cc7c707616..bcb1264f56 100644 --- a/packages/core/src/snackbar/__tests__/Toast.tsx +++ b/packages/core/src/snackbar/__tests__/Toast.tsx @@ -5,7 +5,7 @@ import { screen, userEvent, type RenderResult, -} from "../../test-utils/index.js"; +} from "test-utils"; import { FontIcon } from "../../icon/FontIcon.js"; import { TRANSITION_CONFIG } from "../../transition/config.js"; diff --git a/packages/core/src/snackbar/__tests__/ToastActionButton.tsx b/packages/core/src/snackbar/__tests__/ToastActionButton.tsx index 95eb11d7ea..e3ad03d30b 100644 --- a/packages/core/src/snackbar/__tests__/ToastActionButton.tsx +++ b/packages/core/src/snackbar/__tests__/ToastActionButton.tsx @@ -1,11 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type MouseEvent } from "react"; -import { - render, - rmdRender, - screen, - userEvent, -} from "../../test-utils/index.js"; +import { render, rmdRender, screen, userEvent } from "test-utils"; import { ToastActionButton } from "../ToastActionButton.js"; import { diff --git a/packages/core/src/snackbar/__tests__/ToastCloseButton.tsx b/packages/core/src/snackbar/__tests__/ToastCloseButton.tsx index 2f99dfc33e..25eed04c3d 100644 --- a/packages/core/src/snackbar/__tests__/ToastCloseButton.tsx +++ b/packages/core/src/snackbar/__tests__/ToastCloseButton.tsx @@ -1,11 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef, type MouseEvent } from "react"; -import { - render, - rmdRender, - screen, - userEvent, -} from "../../test-utils/index.js"; +import { render, rmdRender, screen, userEvent } from "test-utils"; import { ToastCloseButton } from "../ToastCloseButton.js"; import { diff --git a/packages/core/src/snackbar/__tests__/ToastContent.tsx b/packages/core/src/snackbar/__tests__/ToastContent.tsx index 5d2192d15d..8b5edd3045 100644 --- a/packages/core/src/snackbar/__tests__/ToastContent.tsx +++ b/packages/core/src/snackbar/__tests__/ToastContent.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { createRef } from "react"; -import { render, screen, waitFor } from "../../test-utils/index.js"; +import { render, screen, waitFor } from "test-utils"; import { ToastContent } from "../ToastContent.js"; diff --git a/packages/core/src/snackbar/__tests__/ToastManagerProvider.tsx b/packages/core/src/snackbar/__tests__/ToastManagerProvider.tsx index e415d5b2d4..6b763177e3 100644 --- a/packages/core/src/snackbar/__tests__/ToastManagerProvider.tsx +++ b/packages/core/src/snackbar/__tests__/ToastManagerProvider.tsx @@ -14,7 +14,7 @@ import { waitFor, within, type RenderResult, -} from "../../test-utils/index.js"; +} from "test-utils"; import { type ReactElement, type ReactNode } from "react"; import { Button } from "../../button/Button.js"; diff --git a/packages/core/src/suspense/__tests__/CircularProgressSuspense.tsx b/packages/core/src/suspense/__tests__/CircularProgressSuspense.tsx index 8adae02f83..9d37052ff8 100644 --- a/packages/core/src/suspense/__tests__/CircularProgressSuspense.tsx +++ b/packages/core/src/suspense/__tests__/CircularProgressSuspense.tsx @@ -1,11 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { lazy, type FC, type ReactElement } from "react"; -import { - act, - render, - screen, - waitForElementToBeRemoved, -} from "../../test-utils/index.js"; +import { act, render, screen, waitForElementToBeRemoved } from "test-utils"; import { Typography } from "../../typography/Typography.js"; import { CircularProgressSuspense, diff --git a/packages/core/src/suspense/__tests__/NullSuspense.tsx b/packages/core/src/suspense/__tests__/NullSuspense.tsx index 8bc579fa7c..c887a3455d 100644 --- a/packages/core/src/suspense/__tests__/NullSuspense.tsx +++ b/packages/core/src/suspense/__tests__/NullSuspense.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { lazy, type FC, type ReactElement } from "react"; -import { act, render, screen, waitFor } from "../../test-utils/index.js"; +import { act, render, screen, waitFor } from "test-utils"; import { Typography } from "../../typography/Typography.js"; import { NullSuspense } from "../NullSuspense.js"; diff --git a/packages/core/src/table/__tests__/Table.tsx b/packages/core/src/table/__tests__/Table.tsx index ec54c96b7f..011bdf1477 100644 --- a/packages/core/src/table/__tests__/Table.tsx +++ b/packages/core/src/table/__tests__/Table.tsx @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { act, render, screen } from "../../test-utils/index.js"; +import { act, render, screen } from "test-utils"; import { type PropsWithRef } from "../../types.js"; import { StickyTableSection } from "../StickyTableSection.js"; diff --git a/packages/core/src/table/__tests__/TableBody.tsx b/packages/core/src/table/__tests__/TableBody.tsx index c798ae9fb9..277917bfa8 100644 --- a/packages/core/src/table/__tests__/TableBody.tsx +++ b/packages/core/src/table/__tests__/TableBody.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Table } from "../Table.js"; import { TableBody } from "../TableBody.js"; diff --git a/packages/core/src/table/__tests__/TableCheckbox.tsx b/packages/core/src/table/__tests__/TableCheckbox.tsx index 4c86f80568..8615e22a9c 100644 --- a/packages/core/src/table/__tests__/TableCheckbox.tsx +++ b/packages/core/src/table/__tests__/TableCheckbox.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type FC, type ReactElement, type ReactNode } from "react"; -import { render, screen, userEvent } from "../../test-utils/index.js"; +import { render, screen, userEvent } from "test-utils"; import { useCheckboxGroup } from "../../form/useCheckboxGroup.js"; import { Table } from "../Table.js"; diff --git a/packages/core/src/table/__tests__/TableContainer.tsx b/packages/core/src/table/__tests__/TableContainer.tsx index afe0811666..40f59b5eee 100644 --- a/packages/core/src/table/__tests__/TableContainer.tsx +++ b/packages/core/src/table/__tests__/TableContainer.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { TableContainer } from "../TableContainer.js"; diff --git a/packages/core/src/table/__tests__/TableRadio.tsx b/packages/core/src/table/__tests__/TableRadio.tsx index a26f1ccb71..d9a242e31c 100644 --- a/packages/core/src/table/__tests__/TableRadio.tsx +++ b/packages/core/src/table/__tests__/TableRadio.tsx @@ -1,7 +1,7 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type FC, type ReactElement, type ReactNode } from "react"; import { useRadioGroup } from "../../form/useRadioGroup.js"; -import { render, screen, userEvent, within } from "../../test-utils/index.js"; +import { render, screen, userEvent, within } from "test-utils"; import { Table } from "../Table.js"; import { TableBody } from "../TableBody.js"; import { TableRadio } from "../TableRadio.js"; diff --git a/packages/core/src/table/__tests__/TableRow.tsx b/packages/core/src/table/__tests__/TableRow.tsx index 18991a4847..1f17cfb200 100644 --- a/packages/core/src/table/__tests__/TableRow.tsx +++ b/packages/core/src/table/__tests__/TableRow.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Table } from "../Table.js"; import { TableBody } from "../TableBody.js"; diff --git a/packages/core/src/tabs/__tests__/Tab.tsx b/packages/core/src/tabs/__tests__/Tab.tsx index beb6caa9d0..7712d849a3 100644 --- a/packages/core/src/tabs/__tests__/Tab.tsx +++ b/packages/core/src/tabs/__tests__/Tab.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { FontIcon } from "../../icon/FontIcon.js"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Tab, type TabProps } from "../Tab.js"; describe("Tab", () => { diff --git a/packages/core/src/tabs/__tests__/TabList.tsx b/packages/core/src/tabs/__tests__/TabList.tsx index d5e1b54164..cc577819d3 100644 --- a/packages/core/src/tabs/__tests__/TabList.tsx +++ b/packages/core/src/tabs/__tests__/TabList.tsx @@ -7,7 +7,7 @@ import { screen, userEvent, waitFor, -} from "../../test-utils/index.js"; +} from "test-utils"; import { DEFAULT_DESKTOP_LARGE_MIN_WIDTH, diff --git a/packages/core/src/tabs/__tests__/useTabs.tsx b/packages/core/src/tabs/__tests__/useTabs.tsx index 5f3e1d6cfe..0c3baf1a47 100644 --- a/packages/core/src/tabs/__tests__/useTabs.tsx +++ b/packages/core/src/tabs/__tests__/useTabs.tsx @@ -1,11 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { type ReactElement } from "react"; -import { - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent, waitFor } from "test-utils"; import { Slide } from "../../transition/Slide.js"; import { SlideContainer } from "../../transition/SlideContainer.js"; diff --git a/packages/core/src/test-utils/index.ts b/packages/core/src/test-utils/index.ts index 9c84dd6b3c..803037c53a 100644 --- a/packages/core/src/test-utils/index.ts +++ b/packages/core/src/test-utils/index.ts @@ -1,8 +1,5 @@ export * from "@testing-library/react"; export * from "@testing-library/user-event"; - -export * from "./IntersectionObserver.js"; -export * from "./ResizeObserver.js"; -export * from "./matchMedia.js"; +export * from "./mocks/match-media.js"; export * from "./render.js"; -export * from "./timers.js"; +export * from "./utils/resize-observer.js"; diff --git a/packages/core/src/test-utils/jest-globals/index.ts b/packages/core/src/test-utils/jest-globals/index.ts new file mode 100644 index 0000000000..8a925c6343 --- /dev/null +++ b/packages/core/src/test-utils/jest-globals/index.ts @@ -0,0 +1,3 @@ +export * from "./match-media.js"; +export * from "./resize-observer.js"; +export * from "./timers.js"; diff --git a/packages/core/src/test-utils/jest-globals/match-media.ts b/packages/core/src/test-utils/jest-globals/match-media.ts new file mode 100644 index 0000000000..232adf267e --- /dev/null +++ b/packages/core/src/test-utils/jest-globals/match-media.ts @@ -0,0 +1,38 @@ +import { jest } from "@jest/globals"; +import { + createMatchMediaSpy, + type MatchMediaChangeViewport, +} from "../mocks/match-media-implementation.js"; +import { matchDesktop, type MatchMediaMatcher } from "../mocks/match-media.js"; + +/** + * @example Default Behavior + * ```tsx + * import { matchPhone, render, spyOnMatchMedia } from "@react-md/core/test-utils/jest-globals"; + * + * const matchMedia = spyOnMatchMedia(); + * render(); + * + * // expect desktop results + * + * matchMedia.changeViewport(matchPhone); + * // expect phone results + * ``` + * + * @example Set Default Media + * ```tsx + * import { matchPhone, render, spyOnMatchMedia } from "@react-md/core/test-utils/jest-globals"; + * + * const matchMedia = spyOnMatchMedia(matchPhone); + * render(); + * + * // expect phone results + * ``` + * + * @since 6.0.0 + */ +export function spyOnMatchMedia( + defaultMatch: MatchMediaMatcher = matchDesktop +): jest.SpiedFunction & MatchMediaChangeViewport { + return createMatchMediaSpy(jest.spyOn(window, "matchMedia"), defaultMatch); +} diff --git a/packages/core/src/test-utils/jest-globals/resize-observer.ts b/packages/core/src/test-utils/jest-globals/resize-observer.ts new file mode 100644 index 0000000000..bbe4a03600 --- /dev/null +++ b/packages/core/src/test-utils/jest-globals/resize-observer.ts @@ -0,0 +1,109 @@ +import { afterEach, jest } from "@jest/globals"; +import { resizeObserverManager } from "../../useResizeObserver.js"; +import { + type SetupResizeObserverMockOptions, + ResizeObserverMock, +} from "../mocks/ResizeObserver.js"; + +/** + * Initializes the `ResizeObserverMock` to be used for tests. + * + * @example Main Usage + * ```tsx + * import { render, screen } from "@react-md/core/test-utils"; + * import { + * cleanupResizeObserverAfterEach, + * setupResizeObserverMock, + * } from "test-utils/jest-globals"; + * import { useResizeObserver } from "@react-md/core/useResizeObserver"; + * import { useCallback, useState } from "react"; + * + * function ExampleComponent() { + * const [size, setSize] = useState({ height: 0, width: 0 }); + * const ref = useResizeObserver({ + * onUpdate: useCallback((entry) => { + * setSize({ + * height: entry.contentRect.height, + * width: entry.contentRect.width, + * }); + * }, []), + * }); + * + * return ( + * <> + *
{JSON.stringify(size)}
+ *
+ * + * ); + * } + * + * cleanupResizeObserverAfterEach(); + * + * describe("ExampleComponent", () => { + * it("should do stuff", () => { + * const observer = setupResizeObserverMock(); + * render(); + * + * const size = screen.getByTestId("size"); + * const resizeTarget = screen.getByTestId("resize-target"); + * + * // jsdom sets all element sizes to 0 by default + * expect(size).toHaveTextContent(JSON.stringify({ height: 0, width: 0 })); + * + * // you can trigger with a custom change + * act(() => { + * observer.resizeElement(resizeTarget, { height: 100, width: 100 }); + * }); + * expect(size).toHaveTextContent(JSON.stringify({ height: 100, width: 100 })); + * + * // or you can mock the `getBoundingClientRect` result + * jest.spyOn(resizeTarget, "getBoundingClientRect").mockReturnValue({ + * ...document.body.getBoundingClientRect(), + * height: 200, + * width: 200, + * }); + * + * act(() => { + * observer.resizeElement(resizeTarget); + * }); + * expect(size).toHaveTextContent(JSON.stringify({ height: 200, width: 200 })); + * }); + * }); + * ``` + * + * @since 6.0.0 + */ +export function setupResizeObserverMock( + options: SetupResizeObserverMockOptions = {} +): ResizeObserverMock { + const { raf, manager = resizeObserverManager } = options; + + const resizeObserver = new ResizeObserverMock((entries) => { + if (raf) { + window.cancelAnimationFrame(manager.frame); + manager.frame = window.requestAnimationFrame(() => { + manager.handleResizeEntries(entries); + }); + } else { + manager.handleResizeEntries(entries); + } + }); + manager.sharedObserver = resizeObserver; + return resizeObserver; +} + +/** + * @see {@link setupResizeObserverMock} + * @since 6.0.0 + */ +export function cleanupResizeObserverAfterEach(restoreAllMocks = true): void { + afterEach(() => { + resizeObserverManager.frame = 0; + resizeObserverManager.subscriptions = new Map(); + resizeObserverManager.sharedObserver = undefined; + + if (restoreAllMocks) { + jest.restoreAllMocks(); + } + }); +} diff --git a/packages/core/src/test-utils/jest-setup.ts b/packages/core/src/test-utils/jest-globals/setup.ts similarity index 69% rename from packages/core/src/test-utils/jest-setup.ts rename to packages/core/src/test-utils/jest-globals/setup.ts index 860def2ffa..93879aefd1 100644 --- a/packages/core/src/test-utils/jest-setup.ts +++ b/packages/core/src/test-utils/jest-globals/setup.ts @@ -1,6 +1,7 @@ import { beforeEach } from "@jest/globals"; -import { INTERACTION_CONFIG } from "../interaction/config.js"; -import { TRANSITION_CONFIG } from "../transition/config.js"; +import "@testing-library/jest-dom/jest-globals"; +import { INTERACTION_CONFIG } from "../../interaction/config.js"; +import { TRANSITION_CONFIG } from "../../transition/config.js"; beforeEach(() => { // set the mode to `none` in tests since ripples require diff --git a/packages/core/src/test-utils/timers.ts b/packages/core/src/test-utils/jest-globals/timers.ts similarity index 86% rename from packages/core/src/test-utils/timers.ts rename to packages/core/src/test-utils/jest-globals/timers.ts index fb7dd1fdd7..3efb573136 100644 --- a/packages/core/src/test-utils/timers.ts +++ b/packages/core/src/test-utils/jest-globals/timers.ts @@ -8,7 +8,7 @@ export type RafSpy = jest.SpiedFunction; /** * @example * ```ts - * import { testImmediateRaf } from "@react-md/core/test-utils"; + * import { testImmediateRaf } from "@react-md/core/test-utils/jest-globals"; * * describe("some test suite", () => { * it("should test something with requestAnimationFrame", () => { @@ -24,7 +24,7 @@ export type RafSpy = jest.SpiedFunction; * * @example Automatic Cleanup * ```ts - * import { testImmediateRaf } from "@react-md/core/test-utils"; + * import { testImmediateRaf } from "@react-md/core/test-utils/jest-globals"; * * afterEach(() => { * jest.restoreAllMocks(); diff --git a/packages/core/src/test-utils/matchMedia.ts b/packages/core/src/test-utils/matchMedia.ts deleted file mode 100644 index 89f97f07dd..0000000000 --- a/packages/core/src/test-utils/matchMedia.ts +++ /dev/null @@ -1,194 +0,0 @@ -import { jest } from "@jest/globals"; -import { act } from "@testing-library/react"; -import { - DEFAULT_DESKTOP_LARGE_MIN_WIDTH, - DEFAULT_DESKTOP_MIN_WIDTH, - DEFAULT_PHONE_MAX_WIDTH, - DEFAULT_TABLET_MIN_WIDTH, -} from "../media-queries/appSize.js"; - -const noop = (): void => { - // do nothing -}; - -/** - * @see {@link spyOnMatchMedia} instead - * @internal - * @since 6.0.0 - */ -export const BASE_MEDIA_QUERY_LIST: MediaQueryList = { - media: "", - matches: false, - onchange: noop, - addListener: noop, - addEventListener: noop, - removeEventListener: noop, - removeListener: noop, - dispatchEvent: () => false, -}; - -/** @since 6.0.0 */ -export type MatchMediaMatcher = (query: string) => boolean; - -/** - * @see {@link spyOnMatchMedia} for usage - * @since 6.0.0 - * @returns `true` for phone media queries - */ -export const matchPhone: MatchMediaMatcher = (query) => - query.includes(DEFAULT_PHONE_MAX_WIDTH); - -/** - * @see {@link spyOnMatchMedia} for usage - * @since 6.0.0 - * @returns `true` for tablet media queries - */ -export const matchTablet: MatchMediaMatcher = (query) => - query.includes(DEFAULT_TABLET_MIN_WIDTH); - -/** - * @see {@link spyOnMatchMedia} for usage - * @since 6.0.0 - * @returns `true` for desktop media queries - */ -export const matchDesktop: MatchMediaMatcher = (query) => - query.includes(DEFAULT_DESKTOP_MIN_WIDTH); - -/** - * @see {@link spyOnMatchMedia} for usage - * @since 6.0.0 - * @returns `true` for large desktop media queries - */ -export const matchLargeDesktop: MatchMediaMatcher = (query) => - query.includes(DEFAULT_DESKTOP_LARGE_MIN_WIDTH); - -/** - * @see {@link spyOnMatchMedia} for usage - * @since 6.0.0 - * @returns `true` for both desktop and large desktop media queries - */ -export const matchAnyDesktop: MatchMediaMatcher = (query) => - matchDesktop(query) || matchLargeDesktop(query); - -/** - * @since 6.0.0 - */ -export type MatchMediaSpiedFunction = jest.SpiedFunction< - typeof window.matchMedia -> & { - /** - * @example Default Behavior - * ```tsx - * const matchMedia = spyOnMatchMedia(); - * render(); - * - * // expect desktop results - * - * matchMedia.changeViewport(matchPhone); - * // expect phone results - * ``` - * - * @example Custom Act Behavior - * ```tsx - * const matchMedia = spyOnMatchMedia(); - * const { rerender } = render(); - * - * // expect desktop results - * - * matchMedia.changeViewport(matchPhone, false); - * rerender(); - * - * // expect phone results - * ``` - */ - changeViewport: (matcher: MatchMediaMatcher, disableAct?: boolean) => void; -}; - -/** - * @example Default Behavior - * ```tsx - * import { matchPhone, render, spyOnMatchMedia } from "@react-md/core/test-utils"; - * - * const matchMedia = spyOnMatchMedia(); - * render(); - * - * // expect desktop results - * - * matchMedia.changeViewport(matchPhone); - * // expect phone results - * ``` - * - * @example Set Default Media - * ```tsx - * import { matchPhone, render, spyOnMatchMedia } from "@react-md/core/test-utils"; - * - * const matchMedia = spyOnMatchMedia(matchPhone); - * render(); - * - * // expect phone results - * ``` - * - * @since 6.0.0 - */ -export function spyOnMatchMedia( - defaultMatch: MatchMediaMatcher = matchDesktop -): MatchMediaSpiedFunction { - type Listener = (event: MediaQueryListEvent) => void; - - const listeners = new Map(); - const matchMedia = jest - .spyOn(window, "matchMedia") - .mockImplementation((query) => ({ - ...BASE_MEDIA_QUERY_LIST, - addEventListener(type: string, listener: Listener | EventListenerObject) { - /* c8 ignore start */ - if (typeof listener !== "function" || type !== "change") { - return; - } - /* c8 ignore stop */ - - listeners.set(query, listener); - }, - removeEventListener( - type: string, - listener: Listener | EventListenerObject - ) { - /* c8 ignore start */ - if (typeof listener !== "function" || type !== "change") { - return; - } - /* c8 ignore stop */ - - listeners.delete(query); - }, - matches: defaultMatch(query), - })); - - const changeViewport = ( - matcher: MatchMediaMatcher, - disableAct = false - ): void => { - const update = (): void => { - window.dispatchEvent(new Event("resize")); - - const event = new Event("change"); - listeners.forEach((listener, query) => { - listener({ - ...event, - media: "", - matches: matcher(query), - }); - }); - }; - if (disableAct) { - update(); - } else { - act(update); - } - }; - - const mock = matchMedia as MatchMediaSpiedFunction; - mock.changeViewport = changeViewport; - - return mock; -} diff --git a/packages/core/src/test-utils/IntersectionObserver.ts b/packages/core/src/test-utils/mocks/IntersectionObserver.ts similarity index 100% rename from packages/core/src/test-utils/IntersectionObserver.ts rename to packages/core/src/test-utils/mocks/IntersectionObserver.ts diff --git a/packages/core/src/test-utils/ResizeObserver.ts b/packages/core/src/test-utils/mocks/ResizeObserver.ts similarity index 81% rename from packages/core/src/test-utils/ResizeObserver.ts rename to packages/core/src/test-utils/mocks/ResizeObserver.ts index c1fbd8dc55..eec06fc0a2 100644 --- a/packages/core/src/test-utils/ResizeObserver.ts +++ b/packages/core/src/test-utils/mocks/ResizeObserver.ts @@ -1,56 +1,12 @@ -import { afterEach, jest } from "@jest/globals"; import { - resizeObserverManager, type ResizeObserverManager, -} from "../useResizeObserver.js"; - -/** - * @since 6.0.0 - */ -export interface ResizeObserverEntrySize { - height?: number; - width?: number; -} - -/** - * @since 6.0.0 - */ -export type GetResizeObserverEntryMock = ( - target: Element, - size?: ResizeObserverEntrySize -) => ResizeObserverEntry; - -/** - * This is mostly an internal function to be used with the {@link ResizeObserverMock} - * and {@link setupResizeObserverMock} - * - * @since 6.0.0 - */ -export const createResizeObserverEntry: GetResizeObserverEntryMock = ( - target, - size -) => { - const contentRect = target.getBoundingClientRect(); - if (typeof size?.height === "number") { - contentRect.height = size.height; - } - if (typeof size?.width === "number") { - contentRect.width = size.width; - } - - const boxSize: ResizeObserverSize = { - blockSize: contentRect.height, - inlineSize: contentRect.width, - }; - - return { - target, - contentRect, - borderBoxSize: [boxSize], - contentBoxSize: [boxSize], - devicePixelContentBoxSize: [], - }; -}; + resizeObserverManager, +} from "../../useResizeObserver.js"; +import { + createResizeObserverEntry, + type GetResizeObserverEntryMock, + type ResizeObserverEntrySize, +} from "../utils/resize-observer.js"; /** * This is the default ResizeObserver implementation if it does not already @@ -88,7 +44,7 @@ export class ResizeObserverMock implements ResizeObserver { * import { * cleanupResizeObserverAfterEach, * setupResizeObserverMock, - * } from "@react-md/core/test-utils"; + * } from "@react-md/core/test-utils/jest-globals"; * import { useResizeObserver } from "@react-md/core"; * import { ExampleComponent } from "../ExampleComponent.js"; * @@ -217,12 +173,11 @@ export interface SetupResizeObserverMockOptions { * * @example Main Usage * ```tsx + * import { render, screen } from "@react-md/core/test-utils"; * import { * cleanupResizeObserverAfterEach, - * render, - * screen, * setupResizeObserverMock, - * } from "@react-md/core/test-utils"; + * } from "test-utils/jest-globals"; * import { useResizeObserver } from "@react-md/core/useResizeObserver"; * import { useCallback, useState } from "react"; * @@ -299,19 +254,3 @@ export function setupResizeObserverMock( manager.sharedObserver = resizeObserver; return resizeObserver; } - -/** - * @see {@link setupResizeObserverMock} - * @since 6.0.0 - */ -export function cleanupResizeObserverAfterEach(restoreAllMocks = true): void { - afterEach(() => { - resizeObserverManager.frame = 0; - resizeObserverManager.subscriptions = new Map(); - resizeObserverManager.sharedObserver = undefined; - - if (restoreAllMocks) { - jest.restoreAllMocks(); - } - }); -} diff --git a/packages/core/src/test-utils/__tests__/ResizeObserver.ts b/packages/core/src/test-utils/mocks/__tests__/ResizeObserver.ts similarity index 95% rename from packages/core/src/test-utils/__tests__/ResizeObserver.ts rename to packages/core/src/test-utils/mocks/__tests__/ResizeObserver.ts index 5911edbc77..e2d5d37213 100644 --- a/packages/core/src/test-utils/__tests__/ResizeObserver.ts +++ b/packages/core/src/test-utils/mocks/__tests__/ResizeObserver.ts @@ -1,14 +1,12 @@ import { describe, expect, it, jest } from "@jest/globals"; import { waitFor } from "@testing-library/react"; +import { createResizeObserverEntry } from "test-utils"; +import { cleanupResizeObserverAfterEach } from "test-utils/jest-globals"; import { ResizeObserverManager, resizeObserverManager, -} from "../../useResizeObserver.js"; -import { - cleanupResizeObserverAfterEach, - createResizeObserverEntry, - setupResizeObserverMock, -} from "../ResizeObserver.js"; +} from "../../../useResizeObserver.js"; +import { setupResizeObserverMock } from "../ResizeObserver.js"; describe("ResizeObserverMock", () => { cleanupResizeObserverAfterEach(); diff --git a/packages/core/src/test-utils/mocks/match-media-implementation.ts b/packages/core/src/test-utils/mocks/match-media-implementation.ts new file mode 100644 index 0000000000..b0cfc32e6c --- /dev/null +++ b/packages/core/src/test-utils/mocks/match-media-implementation.ts @@ -0,0 +1,110 @@ +import { act } from "@testing-library/react"; +import { + BASE_MEDIA_QUERY_LIST, + matchDesktop, + type MatchMediaMatcher, +} from "./match-media.js"; + +/** + * @since 6.0.0 + */ +export interface MatchMediaChangeViewport { + /** + * @example Default Behavior + * ```tsx + * const matchMedia = spyOnMatchMedia(); + * render(); + * + * // expect desktop results + * + * matchMedia.changeViewport(matchPhone); + * // expect phone results + * ``` + * + * @example Custom Act Behavior + * ```tsx + * const matchMedia = spyOnMatchMedia(); + * const { rerender } = render(); + * + * // expect desktop results + * + * matchMedia.changeViewport(matchPhone, false); + * rerender(); + * + * // expect phone results + * ``` + */ + changeViewport: (matcher: MatchMediaMatcher, disableAct?: boolean) => void; +} + +/** + * @since 6.0.0 + */ +export interface MatchMediaMockFunction { + mockImplementation(fn: typeof window.matchMedia): this; +} + +/** + * @since 6.0.0 + */ +export const createMatchMediaSpy = ( + matchMediaSpy: SpyFunction, + defaultMatch: MatchMediaMatcher = matchDesktop +): SpyFunction & MatchMediaChangeViewport => { + type Listener = (event: MediaQueryListEvent) => void; + + const listeners = new Map(); + const matchMedia = matchMediaSpy.mockImplementation((query) => ({ + ...BASE_MEDIA_QUERY_LIST, + addEventListener(type: string, listener: Listener | EventListenerObject) { + /* c8 ignore start */ + if (typeof listener !== "function" || type !== "change") { + return; + } + /* c8 ignore stop */ + + listeners.set(query, listener); + }, + removeEventListener( + type: string, + listener: Listener | EventListenerObject + ) { + /* c8 ignore start */ + if (typeof listener !== "function" || type !== "change") { + return; + } + /* c8 ignore stop */ + + listeners.delete(query); + }, + matches: defaultMatch(query), + })); + + const changeViewport = ( + matcher: MatchMediaMatcher, + disableAct = false + ): void => { + const update = (): void => { + window.dispatchEvent(new Event("resize")); + + const event = new Event("change"); + listeners.forEach((listener, query) => { + listener({ + ...event, + media: "", + matches: matcher(query), + }); + }); + }; + if (disableAct) { + update(); + } else { + act(update); + } + }; + + const mock = matchMedia as SpyFunction & MatchMediaChangeViewport; + mock.changeViewport = changeViewport; + + return mock; +}; diff --git a/packages/core/src/test-utils/mocks/match-media.ts b/packages/core/src/test-utils/mocks/match-media.ts new file mode 100644 index 0000000000..cacd54cea9 --- /dev/null +++ b/packages/core/src/test-utils/mocks/match-media.ts @@ -0,0 +1,63 @@ +import { + DEFAULT_DESKTOP_LARGE_MIN_WIDTH, + DEFAULT_DESKTOP_MIN_WIDTH, + DEFAULT_PHONE_MAX_WIDTH, + DEFAULT_TABLET_MIN_WIDTH, +} from "../../media-queries/appSize.js"; + +const noop = (): void => { + // do nothing +}; + +/** + * @internal + * @since 6.0.0 + */ +export const BASE_MEDIA_QUERY_LIST: MediaQueryList = { + media: "", + matches: false, + onchange: noop, + addListener: noop, + addEventListener: noop, + removeEventListener: noop, + removeListener: noop, + dispatchEvent: () => false, +}; + +/** @since 6.0.0 */ +export type MatchMediaMatcher = (query: string) => boolean; + +/** + * @since 6.0.0 + * @returns `true` for phone media queries + */ +export const matchPhone: MatchMediaMatcher = (query) => + query.includes(DEFAULT_PHONE_MAX_WIDTH); + +/** + * @since 6.0.0 + * @returns `true` for tablet media queries + */ +export const matchTablet: MatchMediaMatcher = (query) => + query.includes(DEFAULT_TABLET_MIN_WIDTH); + +/** + * @since 6.0.0 + * @returns `true` for desktop media queries + */ +export const matchDesktop: MatchMediaMatcher = (query) => + query.includes(DEFAULT_DESKTOP_MIN_WIDTH); + +/** + * @since 6.0.0 + * @returns `true` for large desktop media queries + */ +export const matchLargeDesktop: MatchMediaMatcher = (query) => + query.includes(DEFAULT_DESKTOP_LARGE_MIN_WIDTH); + +/** + * @since 6.0.0 + * @returns `true` for both desktop and large desktop media queries + */ +export const matchAnyDesktop: MatchMediaMatcher = (query) => + matchDesktop(query) || matchLargeDesktop(query); diff --git a/packages/core/src/test-utils/polyfills/IntersectionObserver.ts b/packages/core/src/test-utils/polyfills/IntersectionObserver.ts index f85b6cbdc0..cbb9476322 100644 --- a/packages/core/src/test-utils/polyfills/IntersectionObserver.ts +++ b/packages/core/src/test-utils/polyfills/IntersectionObserver.ts @@ -1,4 +1,4 @@ -import { IntersectionObserverMock } from "../IntersectionObserver.js"; +import { IntersectionObserverMock } from "../mocks/IntersectionObserver.js"; if ( typeof window !== "undefined" && diff --git a/packages/core/src/test-utils/polyfills/ResizeObserver.ts b/packages/core/src/test-utils/polyfills/ResizeObserver.ts index 520b1aa83f..798c768196 100644 --- a/packages/core/src/test-utils/polyfills/ResizeObserver.ts +++ b/packages/core/src/test-utils/polyfills/ResizeObserver.ts @@ -1,4 +1,4 @@ -import { ResizeObserverMock } from "../ResizeObserver.js"; +import { ResizeObserverMock } from "../mocks/ResizeObserver.js"; if (typeof window !== "undefined" && typeof ResizeObserver === "undefined") { window.ResizeObserver = ResizeObserverMock; diff --git a/packages/core/src/test-utils/polyfills/matchMedia.ts b/packages/core/src/test-utils/polyfills/matchMedia.ts index b654fa9a31..9568bb85e6 100644 --- a/packages/core/src/test-utils/polyfills/matchMedia.ts +++ b/packages/core/src/test-utils/polyfills/matchMedia.ts @@ -1,4 +1,4 @@ -import { BASE_MEDIA_QUERY_LIST, matchDesktop } from "../matchMedia.js"; +import { BASE_MEDIA_QUERY_LIST, matchDesktop } from "../mocks/match-media.js"; if (typeof window !== "undefined" && typeof window.matchMedia !== "function") { window.matchMedia = (query) => ({ diff --git a/packages/core/src/test-utils/utils/resize-observer.ts b/packages/core/src/test-utils/utils/resize-observer.ts new file mode 100644 index 0000000000..c2928bcb73 --- /dev/null +++ b/packages/core/src/test-utils/utils/resize-observer.ts @@ -0,0 +1,47 @@ +/** + * @since 6.0.0 + */ +export interface ResizeObserverEntrySize { + height?: number; + width?: number; +} + +/** + * @since 6.0.0 + */ +export type GetResizeObserverEntryMock = ( + target: Element, + size?: ResizeObserverEntrySize +) => ResizeObserverEntry; + +/** + * This is mostly an internal function to be used with the {@link ResizeObserverMock} + * and {@link setupResizeObserverMock} + * + * @since 6.0.0 + */ +export const createResizeObserverEntry: GetResizeObserverEntryMock = ( + target, + size +) => { + const contentRect = target.getBoundingClientRect(); + if (typeof size?.height === "number") { + contentRect.height = size.height; + } + if (typeof size?.width === "number") { + contentRect.width = size.width; + } + + const boxSize: ResizeObserverSize = { + blockSize: contentRect.height, + inlineSize: contentRect.width, + }; + + return { + target, + contentRect, + borderBoxSize: [boxSize], + contentBoxSize: [boxSize], + devicePixelContentBoxSize: [], + }; +}; diff --git a/packages/core/src/theme/__tests__/LocalStorageColorSchemeProvider.tsx b/packages/core/src/theme/__tests__/LocalStorageColorSchemeProvider.tsx index ddb876402f..ff01cce12a 100644 --- a/packages/core/src/theme/__tests__/LocalStorageColorSchemeProvider.tsx +++ b/packages/core/src/theme/__tests__/LocalStorageColorSchemeProvider.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from "@jest/globals"; import { type ChangeEvent, type ReactElement } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { type UseStateSetter } from "../../types.js"; import { LocalStorageColorSchemeProvider } from "../LocalStorageColorSchemeProvider.js"; diff --git a/packages/core/src/theme/__tests__/ThemeProvider.tsx b/packages/core/src/theme/__tests__/ThemeProvider.tsx index 4240101c89..7867cddfab 100644 --- a/packages/core/src/theme/__tests__/ThemeProvider.tsx +++ b/packages/core/src/theme/__tests__/ThemeProvider.tsx @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, jest } from "@jest/globals"; import lodash from "lodash"; -import { render } from "../../test-utils/index.js"; +import { render } from "test-utils"; import { DEFAULT_DARK_THEME, diff --git a/packages/core/src/theme/__tests__/useCSSVariables.tsx b/packages/core/src/theme/__tests__/useCSSVariables.tsx index fdfb79c95e..025006b38c 100644 --- a/packages/core/src/theme/__tests__/useCSSVariables.tsx +++ b/packages/core/src/theme/__tests__/useCSSVariables.tsx @@ -7,7 +7,7 @@ import { type ReactElement, type RefObject, } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { textPrimaryColorVar } from "../cssVars.js"; import { diff --git a/packages/core/src/theme/__tests__/useColorSchemeMetaTag.tsx b/packages/core/src/theme/__tests__/useColorSchemeMetaTag.tsx index a6b83f7db4..2af37f406e 100644 --- a/packages/core/src/theme/__tests__/useColorSchemeMetaTag.tsx +++ b/packages/core/src/theme/__tests__/useColorSchemeMetaTag.tsx @@ -1,5 +1,5 @@ import { describe, expect, it } from "@jest/globals"; -import { render } from "../../test-utils/index.js"; +import { render } from "test-utils"; import { useColorSchemeMetaTag, type ColorSchemeMetaTagOptions, diff --git a/packages/core/src/tooltip/__tests__/Tooltip.tsx b/packages/core/src/tooltip/__tests__/Tooltip.tsx index 1b4fc9208a..4489581788 100644 --- a/packages/core/src/tooltip/__tests__/Tooltip.tsx +++ b/packages/core/src/tooltip/__tests__/Tooltip.tsx @@ -15,7 +15,7 @@ import { userEvent, waitFor, waitForElementToBeRemoved, -} from "../../test-utils/index.js"; +} from "test-utils"; import { Button } from "../../button/Button.js"; import { FontIcon } from "../../icon/FontIcon.js"; diff --git a/packages/core/src/tooltip/__tests__/TooltipHoverModeProvider.tsx b/packages/core/src/tooltip/__tests__/TooltipHoverModeProvider.tsx index e641d14870..e56e7fc539 100644 --- a/packages/core/src/tooltip/__tests__/TooltipHoverModeProvider.tsx +++ b/packages/core/src/tooltip/__tests__/TooltipHoverModeProvider.tsx @@ -6,7 +6,7 @@ import { userEvent, waitFor, waitForElementToBeRemoved, -} from "../../test-utils/index.js"; +} from "test-utils"; import { Button } from "../../button/Button.js"; import { TRANSITION_CONFIG } from "../../transition/config.js"; diff --git a/packages/core/src/transition/__tests__/CSSTransition.tsx b/packages/core/src/transition/__tests__/CSSTransition.tsx index 42467dd35c..5e342ea14c 100644 --- a/packages/core/src/transition/__tests__/CSSTransition.tsx +++ b/packages/core/src/transition/__tests__/CSSTransition.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { CSSTransition, type CSSTransitionProps } from "../CSSTransition.js"; import { TRANSITION_CONFIG } from "../config.js"; diff --git a/packages/core/src/transition/__tests__/Collapse.tsx b/packages/core/src/transition/__tests__/Collapse.tsx index a4e193583c..11cd2d9b85 100644 --- a/packages/core/src/transition/__tests__/Collapse.tsx +++ b/packages/core/src/transition/__tests__/Collapse.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { DISPLAY_NONE_CLASS } from "../../utils/isElementVisible.js"; import { Collapse, type CollapseProps } from "../Collapse.js"; diff --git a/packages/core/src/transition/__tests__/CrossFade.tsx b/packages/core/src/transition/__tests__/CrossFade.tsx index 6d39a11d13..65aefe1da8 100644 --- a/packages/core/src/transition/__tests__/CrossFade.tsx +++ b/packages/core/src/transition/__tests__/CrossFade.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { CrossFade, type CrossFadeProps } from "../CrossFade.js"; import { TRANSITION_CONFIG } from "../config.js"; diff --git a/packages/core/src/transition/__tests__/ScaleTransition.tsx b/packages/core/src/transition/__tests__/ScaleTransition.tsx index dbf1b76aec..defbfe9e81 100644 --- a/packages/core/src/transition/__tests__/ScaleTransition.tsx +++ b/packages/core/src/transition/__tests__/ScaleTransition.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { ScaleTransition, diff --git a/packages/core/src/transition/__tests__/SkeletonPlaceholder.tsx b/packages/core/src/transition/__tests__/SkeletonPlaceholder.tsx index 53b101c183..ff55e46cdc 100644 --- a/packages/core/src/transition/__tests__/SkeletonPlaceholder.tsx +++ b/packages/core/src/transition/__tests__/SkeletonPlaceholder.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef, type ReactElement } from "react"; -import { render, rmdRender, screen } from "../../test-utils/index.js"; +import { render, rmdRender, screen } from "test-utils"; import { type NonNullMutableRef } from "../../types.js"; import { SkeletonPlaceholder } from "../SkeletonPlaceholder.js"; import { diff --git a/packages/core/src/transition/__tests__/useCSSTransition.tsx b/packages/core/src/transition/__tests__/useCSSTransition.tsx index ae65d1c3e0..a6a8acb7d6 100644 --- a/packages/core/src/transition/__tests__/useCSSTransition.tsx +++ b/packages/core/src/transition/__tests__/useCSSTransition.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { TRANSITION_CONFIG } from "../config.js"; import { diff --git a/packages/core/src/transition/__tests__/useCollapseTransition.tsx b/packages/core/src/transition/__tests__/useCollapseTransition.tsx index 201834f022..43d7d4f976 100644 --- a/packages/core/src/transition/__tests__/useCollapseTransition.tsx +++ b/packages/core/src/transition/__tests__/useCollapseTransition.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { DISPLAY_NONE_CLASS } from "../../utils/isElementVisible.js"; import { TRANSITION_CONFIG } from "../config.js"; diff --git a/packages/core/src/transition/__tests__/useCrossFadeTransition.tsx b/packages/core/src/transition/__tests__/useCrossFadeTransition.tsx index bcc33d4c54..6788bc0bd0 100644 --- a/packages/core/src/transition/__tests__/useCrossFadeTransition.tsx +++ b/packages/core/src/transition/__tests__/useCrossFadeTransition.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { TRANSITION_CONFIG } from "../config.js"; import { diff --git a/packages/core/src/transition/__tests__/useMaxWidthTransition.tsx b/packages/core/src/transition/__tests__/useMaxWidthTransition.tsx index 64ec39ac88..5d2508e438 100644 --- a/packages/core/src/transition/__tests__/useMaxWidthTransition.tsx +++ b/packages/core/src/transition/__tests__/useMaxWidthTransition.tsx @@ -2,7 +2,7 @@ import { describe, expect, it } from "@jest/globals"; import { type ReactElement } from "react"; import { Button } from "../../button/Button.js"; import { FontIcon } from "../../icon/FontIcon.js"; -import { rmdRender, screen, userEvent } from "../../test-utils/index.js"; +import { rmdRender, screen, userEvent } from "test-utils"; import { useToggle } from "../../useToggle.js"; import { DISPLAY_NONE_CLASS } from "../../utils/isElementVisible.js"; import { useMaxWidthTransition } from "../useMaxWidthTransition.js"; diff --git a/packages/core/src/transition/__tests__/useScaleTransition.tsx b/packages/core/src/transition/__tests__/useScaleTransition.tsx index b2c3e7d1f3..b3bbf23133 100644 --- a/packages/core/src/transition/__tests__/useScaleTransition.tsx +++ b/packages/core/src/transition/__tests__/useScaleTransition.tsx @@ -8,7 +8,7 @@ import { jest, } from "@jest/globals"; import { useState, type ReactElement } from "react"; -import { act, fireEvent, render, screen } from "../../test-utils/index.js"; +import { act, fireEvent, render, screen } from "test-utils"; import { TRANSITION_CONFIG } from "../config.js"; import { diff --git a/packages/core/src/transition/__tests__/useTransition.tsx b/packages/core/src/transition/__tests__/useTransition.tsx index e343331efd..ac7acf2992 100644 --- a/packages/core/src/transition/__tests__/useTransition.tsx +++ b/packages/core/src/transition/__tests__/useTransition.tsx @@ -13,13 +13,7 @@ import { type MutableRefObject, type ReactElement, } from "react"; -import { - act, - fireEvent, - render, - screen, - waitFor, -} from "../../test-utils/index.js"; +import { act, fireEvent, render, screen, waitFor } from "test-utils"; import { SsrProvider, useSsr } from "../../SsrProvider.js"; import { useLocalStorage } from "../../useLocalStorage.js"; diff --git a/packages/core/src/tree/__tests__/Tree.tsx b/packages/core/src/tree/__tests__/Tree.tsx index e351e9c57e..53e99c3aa6 100644 --- a/packages/core/src/tree/__tests__/Tree.tsx +++ b/packages/core/src/tree/__tests__/Tree.tsx @@ -5,13 +5,7 @@ import { type AnchorHTMLAttributes, type ReactElement, } from "react"; -import { - fireEvent, - rmdRender, - screen, - userEvent, - waitFor, -} from "../../test-utils/index.js"; +import { fireEvent, rmdRender, screen, userEvent, waitFor } from "test-utils"; import { Divider } from "../../divider/Divider.js"; import { FontIcon } from "../../icon/FontIcon.js"; diff --git a/packages/core/src/tree/__tests__/TreeGroup.tsx b/packages/core/src/tree/__tests__/TreeGroup.tsx index c1a6f900c7..a4937b6ab8 100644 --- a/packages/core/src/tree/__tests__/TreeGroup.tsx +++ b/packages/core/src/tree/__tests__/TreeGroup.tsx @@ -1,5 +1,5 @@ import { describe, expect, it, jest } from "@jest/globals"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { TreeGroup } from "../TreeGroup.js"; import { TreeItem } from "../TreeItem.js"; diff --git a/packages/core/src/tree/__tests__/TreeItemExpander.tsx b/packages/core/src/tree/__tests__/TreeItemExpander.tsx index df089bb231..373d88a6cd 100644 --- a/packages/core/src/tree/__tests__/TreeItemExpander.tsx +++ b/packages/core/src/tree/__tests__/TreeItemExpander.tsx @@ -1,5 +1,5 @@ import { describe, expect, it, jest } from "@jest/globals"; -import { fireEvent, render } from "../../test-utils/index.js"; +import { fireEvent, render } from "test-utils"; import { TreeItemExpander } from "../TreeItemExpander.js"; import { TreeProvider } from "../TreeProvider.js"; diff --git a/packages/core/src/typography/__tests__/SrOnly.tsx b/packages/core/src/typography/__tests__/SrOnly.tsx index 769b9633de..d6dce310bb 100644 --- a/packages/core/src/typography/__tests__/SrOnly.tsx +++ b/packages/core/src/typography/__tests__/SrOnly.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render } from "../../test-utils/index.js"; +import { render } from "test-utils"; import { SrOnly } from "../SrOnly.js"; diff --git a/packages/core/src/typography/__tests__/TextContainer.tsx b/packages/core/src/typography/__tests__/TextContainer.tsx index b191750aeb..5edaf865a3 100644 --- a/packages/core/src/typography/__tests__/TextContainer.tsx +++ b/packages/core/src/typography/__tests__/TextContainer.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { createRef } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { TextContainer } from "../TextContainer.js"; import { Typography } from "../Typography.js"; diff --git a/packages/core/src/typography/__tests__/Typography.tsx b/packages/core/src/typography/__tests__/Typography.tsx index 5cc3471856..79d4bcdd6e 100644 --- a/packages/core/src/typography/__tests__/Typography.tsx +++ b/packages/core/src/typography/__tests__/Typography.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type HTMLAttributes, type ReactElement } from "react"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { Typography } from "../Typography.js"; import { typography, type TypographyType } from "../typographyStyles.js"; diff --git a/packages/core/src/typography/__tests__/WritingDirectionProvider.tsx b/packages/core/src/typography/__tests__/WritingDirectionProvider.tsx index aa810e5e8a..4e04684d4b 100644 --- a/packages/core/src/typography/__tests__/WritingDirectionProvider.tsx +++ b/packages/core/src/typography/__tests__/WritingDirectionProvider.tsx @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; import { type FC } from "react"; -import { fireEvent, render, screen } from "../../test-utils/index.js"; +import { fireEvent, render, screen } from "test-utils"; import { useDir, diff --git a/packages/core/src/utils/__tests__/RenderRecursively.tsx b/packages/core/src/utils/__tests__/RenderRecursively.tsx index 74a9e1385b..3f7a2d09dc 100644 --- a/packages/core/src/utils/__tests__/RenderRecursively.tsx +++ b/packages/core/src/utils/__tests__/RenderRecursively.tsx @@ -3,7 +3,7 @@ import { cnb } from "cnbuilder"; import { type ReactElement } from "react"; import { Divider } from "../../divider/Divider.js"; import { List } from "../../list/List.js"; -import { render, screen } from "../../test-utils/index.js"; +import { render, screen } from "test-utils"; import { type RenderRecursiveItemsProps, RenderRecursively, diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index c9e930167c..84013ac70d 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": ".", "target": "esnext", "module": "nodenext", "strict": true, @@ -14,7 +15,11 @@ "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "jsx": "preserve", - "lib": ["dom", "dom.iterable", "esnext"] + "lib": ["dom", "dom.iterable", "esnext"], + "paths": { + "test-utils/jest-globals": ["./src/test-utils/jest-globals/index.ts"], + "test-utils": ["./src/test-utils/index.ts"] + } }, "exclude": ["node_modules", "dist"] }