forked from colinhacks/zod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:vriad/zod
- Loading branch information
Showing
11 changed files
with
256 additions
and
4 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,43 @@ | ||
// @ts-ignore TS6133 | ||
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import { util } from "../helpers/util.ts"; | ||
import * as z from "../index.ts"; | ||
|
||
const fish = z.object({ | ||
name: z.string(), | ||
age: z.number(), | ||
nested: z.object({}), | ||
}); | ||
|
||
test("partial by type inference", () => { | ||
const optionalNameFish = fish.partialBy({ name: true }); | ||
type optionalNameFish = z.infer<typeof optionalNameFish>; | ||
const f1: util.AssertEqual< | ||
optionalNameFish, | ||
{ name?: string | undefined; age: number; nested: {} } | ||
> = true; | ||
f1; | ||
}); | ||
|
||
test("partial by parse - success", () => { | ||
const nameOptionalFish = fish.partialBy({ name: true }); | ||
nameOptionalFish.parse({ age: 0, nested: {} }); | ||
}); | ||
|
||
test("partial by parse - fail", () => { | ||
fish.partialBy({ name: true, age: true }).parse({ nested: {} } as any); | ||
fish | ||
.partialBy({ name: true }) | ||
.parse({ name: "bob", age: 12, nested: {} } as any); | ||
fish.partialBy({ name: true }).parse({ age: 12, nested: {} } as any); | ||
|
||
const nameOptionalFish = fish.partialBy({ name: true }); | ||
const bad1 = () => | ||
nameOptionalFish.parse({ name: 12, age: 12, nested: {} } as any); | ||
const bad2 = () => nameOptionalFish.parse({ age: 12 } as any); | ||
|
||
expect(bad1).toThrow(); | ||
expect(bad2).toThrow(); | ||
}); |
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
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,42 @@ | ||
// @ts-ignore TS6133 | ||
import { expect, test } from "@jest/globals"; | ||
|
||
import { util } from "../helpers/util"; | ||
import * as z from "../index"; | ||
|
||
const fish = z.object({ | ||
name: z.string(), | ||
age: z.number(), | ||
nested: z.object({}), | ||
}); | ||
|
||
test("partial by type inference", () => { | ||
const optionalNameFish = fish.partialBy({ name: true }); | ||
type optionalNameFish = z.infer<typeof optionalNameFish>; | ||
const f1: util.AssertEqual< | ||
optionalNameFish, | ||
{ name?: string | undefined; age: number; nested: {} } | ||
> = true; | ||
f1; | ||
}); | ||
|
||
test("partial by parse - success", () => { | ||
const nameOptionalFish = fish.partialBy({ name: true }); | ||
nameOptionalFish.parse({ age: 0, nested: {} }); | ||
}); | ||
|
||
test("partial by parse - fail", () => { | ||
fish.partialBy({ name: true, age: true }).parse({ nested: {} } as any); | ||
fish | ||
.partialBy({ name: true }) | ||
.parse({ name: "bob", age: 12, nested: {} } as any); | ||
fish.partialBy({ name: true }).parse({ age: 12, nested: {} } as any); | ||
|
||
const nameOptionalFish = fish.partialBy({ name: true }); | ||
const bad1 = () => | ||
nameOptionalFish.parse({ name: 12, age: 12, nested: {} } as any); | ||
const bad2 = () => nameOptionalFish.parse({ age: 12 } as any); | ||
|
||
expect(bad1).toThrow(); | ||
expect(bad2).toThrow(); | ||
}); |
Oops, something went wrong.