-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f56ac90
commit 1b6f34c
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/core/src/__tests__/unit/utils/getRefFromChildren.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters