-
Notifications
You must be signed in to change notification settings - Fork 10
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
20ae127
commit faf68ae
Showing
7 changed files
with
143 additions
and
61 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,41 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { Equal, Expect, accept } from "./test-utils"; | ||
import { fromAny } from "../src"; | ||
|
||
describe("fromAny", () => { | ||
it("Should return whatever you pass in", () => { | ||
const result = fromAny({ foo: "bar" }); | ||
|
||
expect(result).toEqual({ foo: "bar" }); | ||
}); | ||
|
||
it("Should return unknown if not called in a function's args", () => { | ||
const result = fromAny({ foo: "bar" }); | ||
|
||
type test = Expect<Equal<typeof result, unknown>>; | ||
}); | ||
|
||
it("Should let you pass anything to a function", () => { | ||
accept<{ foo: string; bar: number }>(fromAny("str")); | ||
|
||
accept<{ foo: string; bar: number }>(fromAny(124123)); | ||
|
||
accept<{ foo: string; bar: number }>( | ||
fromAny({ | ||
foo: "awdaw", | ||
}), | ||
); | ||
}); | ||
|
||
it("When passed into a function, it should NOT give excess property warnings", () => { | ||
accept<{ | ||
foo: string; | ||
bar: number; | ||
}>( | ||
fromAny({ | ||
foo: "bar", | ||
baz: 1, | ||
}), | ||
); | ||
}); | ||
}); |
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,26 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { fromAny, fromExact, fromPartial } from "../src"; | ||
import { Equal, Expect, accept } from "./test-utils"; | ||
|
||
describe("fromExact", () => { | ||
it("Should return whatever you pass in", () => { | ||
const result = fromExact({ foo: "bar" }); | ||
|
||
expect(result).toEqual({ foo: "bar" }); | ||
}); | ||
|
||
it("Should return the type you pass in", () => { | ||
const result = fromExact({ foo: "bar" }); | ||
|
||
type test = Expect<Equal<typeof result, { foo: string }>>; | ||
}); | ||
|
||
it("When passed to a function, it should expect the exact type", () => { | ||
accept<{ foo: string; bar: number }>( | ||
// @ts-expect-error | ||
fromExact({ | ||
foo: "bar", | ||
}), | ||
); | ||
}); | ||
}); |
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
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