Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Jul 8, 2024
1 parent f56ac90 commit 1b6f34c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions packages/core/src/__tests__/unit/utils/getRefFromChildren.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getRefFromChildren } from "@salt-ds/core";
import { describe, it, expect } from "vitest";
import { ReactNode } from "react";

describe("getRefFromChildren", () => {
it("should return null if child is not a valid element", () => {
expect(getRefFromChildren(null)).toBeNull();
expect(getRefFromChildren(undefined)).toBeNull();
expect(getRefFromChildren("string")).toBeNull();
expect(getRefFromChildren(123)).toBeNull();
expect(getRefFromChildren(<></>)).toBeNull();
expect(getRefFromChildren([])).toBeNull();
});

it("should return null if ref is not defined", () => {
const child = <button />;
expect(getRefFromChildren(child)).toBeNull();
});

it("should return ref from child", () => {
const ref = () => {};
const child = <button ref={ref} />;
expect(getRefFromChildren(child)).toBe(ref);
});
});
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
include: ["**/*.spec.[jt]s"],
include: ["**/*.spec.[jt]s(x)"],
},
});

0 comments on commit 1b6f34c

Please sign in to comment.