From 2911102eead7e623f2e2f432f596b4cefcc99d88 Mon Sep 17 00:00:00 2001 From: Ryan Gossiaux Date: Thu, 30 Dec 2021 16:36:37 -1000 Subject: [PATCH] Add Description tests --- .../description/description.test.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/lib/components/description/description.test.ts diff --git a/src/lib/components/description/description.test.ts b/src/lib/components/description/description.test.ts new file mode 100644 index 0000000..1fc58a9 --- /dev/null +++ b/src/lib/components/description/description.test.ts @@ -0,0 +1,106 @@ +import DescriptionProvider from "./DescriptionProvider.svelte"; +import Description from "./Description.svelte"; +import svelte from "svelte-inline-compile"; +import { render } from "@testing-library/svelte"; + +let mockId = 0; +jest.mock("../../hooks/use-id", () => { + return { + useId: jest.fn(() => ++mockId), + }; +}); + +beforeEach(() => (mockId = 0)); +beforeAll(() => { + // jest.spyOn(window, 'requestAnimationFrame').mockImplementation(setImmediate as any) + // jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(clearImmediate as any) +}); +afterAll(() => jest.restoreAllMocks()); + +it("should be possible to render a DescriptionProvider", () => { + render(DescriptionProvider, { name: "test" }); + // This dumb line is to trick the TS compiler to not remove my imports + expect(DescriptionProvider).not.toBe(Description); +}); + +it("should be possible to use a DescriptionProvider without using a Description", async () => { + let { container } = render(svelte` + +
+ No description +
+
+ `); + + expect(container.firstChild?.firstChild).toMatchInlineSnapshot(` +
+ No description +
+ `); +}); + +it("should be possible to use a DescriptionProvider and a single Description, and have them linked", async () => { + let { container } = render(svelte` + +
+ I am a description + Contents +
+
+ `); + + expect(container.firstChild?.firstChild).toMatchInlineSnapshot(` +
+

+ I am a description +

+ + + + + Contents + +
+ `); +}); + +it("should be possible to use a DescriptionProvider and multiple Description components, and have them linked", async () => { + let { container } = render(svelte` + +
+ I am a description + Contents + I am also a description +
+
+ `); + expect(container.firstChild?.firstChild).toMatchInlineSnapshot(` +
+

+ I am a description +

+ + + + + Contents + + +

+ I am also a description +

+ + +
+ `); +});