diff --git a/package.json b/package.json index 9cd1638f..84cf2c6b 100644 --- a/package.json +++ b/package.json @@ -90,13 +90,12 @@ }, "dependencies": { "@types/jest": "29.5.11", - "@types/node": "18.19.4", + "@types/node": "20.8.5", "@types/react": "18.2.46", "@types/react-dom": "18.2.18", "@types/react-table": "7.7.19", "classnames": "2.5.1", "jest-environment-jsdom": "29.7.0", - "nanoid": "5.0.4", "prop-types": "15.8.1", "react-table": "7.8.0", "react-useportal": "1.0.19" diff --git a/src/__mocks__/nanoid.ts b/src/__mocks__/nanoid.ts deleted file mode 100644 index afa970a6..00000000 --- a/src/__mocks__/nanoid.ts +++ /dev/null @@ -1,10 +0,0 @@ -let id = 0; - -beforeEach(() => { - id = 0; -}); - -export const nanoid = (): string => { - id++; - return `mock-nanoid-${id}`; -}; diff --git a/src/components/Accordion/Accordion.test.tsx b/src/components/Accordion/Accordion.test.tsx index 8f5aa3ea..42c5d9b0 100644 --- a/src/components/Accordion/Accordion.test.tsx +++ b/src/components/Accordion/Accordion.test.tsx @@ -1,15 +1,10 @@ import React from "react"; -import * as nanoid from "nanoid"; import Accordion from "./Accordion"; import { render, screen, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; describe("Accordion", () => { - beforeEach(() => { - jest.spyOn(nanoid, "nanoid").mockReturnValueOnce("mocked-nanoid"); - }); - afterEach(() => { jest.restoreAllMocks(); }); @@ -69,10 +64,7 @@ describe("Accordion", () => { ); const tab = screen.getByRole("tab", { name: "Advanced topics" }); await userEvent.click(tab); - expect(onExpandedChange).toHaveBeenCalledWith( - "mocked-nanoid", - "Advanced topics" - ); + expect(onExpandedChange).toHaveBeenCalledWith(":r6:", "Advanced topics"); // Clicking the tab again should close the accordion section. await userEvent.click(tab); expect(onExpandedChange).toHaveBeenCalledWith(null, null); diff --git a/src/components/Accordion/AccordionSection/AccordionSection.test.tsx b/src/components/Accordion/AccordionSection/AccordionSection.test.tsx index a2847ed4..d30a4de6 100644 --- a/src/components/Accordion/AccordionSection/AccordionSection.test.tsx +++ b/src/components/Accordion/AccordionSection/AccordionSection.test.tsx @@ -50,7 +50,7 @@ describe("AccordionSection ", () => { /> ); await userEvent.click(screen.getByRole("tab", { name: "Test section" })); - expect(onTitleClick).toHaveBeenCalledWith(true, "mock-nanoid-1"); + expect(onTitleClick).toHaveBeenCalledWith(true, ":r4:"); rerender( Test} @@ -65,7 +65,7 @@ describe("AccordionSection ", () => { // Clicking the title again should close the accordion section. await userEvent.click(screen.getByRole("tab", { name: "Test section" })); - expect(onTitleClick.mock.calls[1]).toEqual([false, "mock-nanoid-1"]); + expect(onTitleClick.mock.calls[1]).toEqual([false, ":r4:"]); }); it("can use a key for expanded state", async () => { diff --git a/src/components/Accordion/AccordionSection/AccordionSection.tsx b/src/components/Accordion/AccordionSection/AccordionSection.tsx index 991cd384..fcf4b234 100644 --- a/src/components/Accordion/AccordionSection/AccordionSection.tsx +++ b/src/components/Accordion/AccordionSection/AccordionSection.tsx @@ -1,8 +1,7 @@ -import React from "react"; +import React, { useId } from "react"; import type { ReactNode } from "react"; import type { Headings } from "types"; -import { useId } from "hooks/useId"; export type AccordionHeadings = Exclude; diff --git a/src/components/Accordion/AccordionSection/__snapshots__/AccordionSection.test.tsx.snap b/src/components/Accordion/AccordionSection/__snapshots__/AccordionSection.test.tsx.snap index 635e370a..57ebcbee 100644 --- a/src/components/Accordion/AccordionSection/__snapshots__/AccordionSection.test.tsx.snap +++ b/src/components/Accordion/AccordionSection/__snapshots__/AccordionSection.test.tsx.snap @@ -10,10 +10,10 @@ exports[`AccordionSection renders 1`] = ` role="heading" >