-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
edc3a67
commit e59f639
Showing
5 changed files
with
75 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @ts-ignore TS6133 | ||
import { expect } from "https://deno.land/x/[email protected]/mod.ts"; | ||
const test = Deno.test; | ||
|
||
import * as z from "../index.ts"; | ||
|
||
test("passing validations", () => { | ||
const example1 = z.custom<number>((x) => typeof x === "number"); | ||
example1.parse(1234); | ||
expect(() => example1.parse({})).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
import { z } from "./src"; | ||
const example1 = z.custom<number>((x) => typeof x === "number"); | ||
example1.parse("asdf"); | ||
// const example1 = z | ||
// .custom<number>( | ||
// (x) => { | ||
// console.log(`custom`); | ||
// console.log(x); | ||
// return typeof x === "number"; | ||
// }, | ||
// {}, | ||
// true | ||
// ) | ||
// .transform((x) => { | ||
// console.log(`transform`); | ||
// console.log(x); | ||
// return String(x); | ||
// }) | ||
// .refine((x) => { | ||
// console.log(`refine`); | ||
// console.log(x); | ||
// console.log(typeof x); // prints 'Object' | ||
// console.log("I get called even though I shouldn't!!!"); | ||
// return true; | ||
// }) | ||
// .safeParse({}); //will fail because it is not a number | ||
|
||
// benchmark | ||
// run 10000 times | ||
console.time("bench"); | ||
for (let i = 0; i < 10000; i++) { | ||
z.string().catch("asdf").parse(5); | ||
} | ||
console.timeEnd("bench"); | ||
// console.log(example1.success); // false (like it should be) |
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,10 @@ | ||
// @ts-ignore TS6133 | ||
import { expect, test } from "@jest/globals"; | ||
|
||
import * as z from "../index"; | ||
|
||
test("passing validations", () => { | ||
const example1 = z.custom<number>((x) => typeof x === "number"); | ||
example1.parse(1234); | ||
expect(() => example1.parse({})).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