|
| 1 | +import { asGhostProps } from "../maybeGhost"; |
| 2 | +import { isReactGhost } from "../types"; |
| 3 | +import { expect, test } from "vitest"; |
| 4 | + |
| 5 | +interface Props { |
| 6 | + first: string; |
| 7 | + second?: string; |
| 8 | + third: string | undefined; |
| 9 | +} |
| 10 | + |
| 11 | +test("makes Ghosts of all props", () => { |
| 12 | + const ghostProps = asGhostProps<Props>({ |
| 13 | + first: "hello", |
| 14 | + second: "world", |
| 15 | + third: "!", |
| 16 | + }); |
| 17 | + |
| 18 | + expect(ghostProps.firstGhost).toSatisfy(isReactGhost); |
| 19 | + expect(ghostProps.secondGhost).toSatisfy(isReactGhost); |
| 20 | + expect(ghostProps.thirdGhost).toSatisfy(isReactGhost); |
| 21 | +}); |
| 22 | + |
| 23 | +test("does not make Ghosts of explicit undefined", () => { |
| 24 | + const ghostProps = asGhostProps<Props>({ |
| 25 | + first: "hello", |
| 26 | + second: undefined, |
| 27 | + third: "!", |
| 28 | + }); |
| 29 | + |
| 30 | + expect(ghostProps.firstGhost).toSatisfy(isReactGhost); |
| 31 | + expect(ghostProps.secondGhost).toBeUndefined(); |
| 32 | + expect(ghostProps.thirdGhost).toSatisfy(isReactGhost); |
| 33 | +}); |
| 34 | + |
| 35 | +test("does not make Ghosts of not given props", () => { |
| 36 | + const ghostProps = asGhostProps<Props>({ |
| 37 | + first: "hello", |
| 38 | + third: "!", |
| 39 | + }); |
| 40 | + |
| 41 | + expect(ghostProps.firstGhost).toSatisfy(isReactGhost); |
| 42 | + expect(ghostProps.secondGhost).toBeUndefined(); |
| 43 | + expect(ghostProps.thirdGhost).toSatisfy(isReactGhost); |
| 44 | +}); |
| 45 | + |
| 46 | +test("does not make Ghosts of excluded props", () => { |
| 47 | + const ghostProps = asGhostProps<Props>( |
| 48 | + { |
| 49 | + first: "hello", |
| 50 | + second: "world", |
| 51 | + third: "!", |
| 52 | + }, |
| 53 | + ["first"], |
| 54 | + ); |
| 55 | + |
| 56 | + expect(ghostProps.firstGhost).toSatisfy(isReactGhost); |
| 57 | + expect(ghostProps.secondGhost).not.toSatisfy(isReactGhost); |
| 58 | + expect(ghostProps.thirdGhost).not.toSatisfy(isReactGhost); |
| 59 | +}); |
0 commit comments