diff --git a/src/lib/components/label/label.test.ts b/src/lib/components/label/label.test.ts new file mode 100644 index 0000000..dbfb1c8 --- /dev/null +++ b/src/lib/components/label/label.test.ts @@ -0,0 +1,66 @@ +import { render } from "@testing-library/svelte"; +import Label from "./Label.svelte"; +import LabelProvider from "./LabelProvider.svelte"; +import svelte from "svelte-inline-compile"; + +let mockId = 0; +jest.mock("../../hooks/use-id", () => { + return { + useId: jest.fn(() => ++mockId), + }; +}); + +beforeEach(() => (mockId = 0)); +afterAll(() => jest.restoreAllMocks()); + +it("should be possible to use a LabelProvider without using a Label", async () => { + let { container } = render(svelte` + +
+ No label +
+
+`); + expect(container.firstChild?.firstChild).toMatchInlineSnapshot(` +
+ No label +
+ `); +}); + +it("should be possible to use a LabelProvider and a single Label, and have them linked", async () => { + let { container } = render(svelte` + + +
+ Contents +
+
+`); + expect(container.firstChild?.firstChild).toMatchInlineSnapshot(` + + `); +}); + +it("should be possible to use a LabelProvider and multiple Label components, and have them linked", async () => { + let { container } = render(svelte` + + +
+ Contents +
+ +
+`); + expect(container.firstChild?.firstChild).toMatchInlineSnapshot(` + + `); +});