-
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.
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -36,5 +36,4 @@ createMock(schema); // { name: string, age: number } | |
## TODO | ||
|
||
- ZodNever | ||
- ZodFunction | ||
- ZodLazy |
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,10 @@ | ||
import type { z } from 'zod'; | ||
import MockGenerator from '../MockGenerator'; | ||
import type BaseGenerator from './BaseGenerator'; | ||
|
||
export default class FunctionGenerator<T extends z.ZodFunction<z.ZodTuple<any, any>, z.ZodTypeAny>> implements BaseGenerator<T> { | ||
public generate(schema: T): z.infer<typeof schema> { | ||
const mockGenerator = new MockGenerator(schema._def.returns); | ||
return () => mockGenerator.generate(); | ||
} | ||
} |
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,31 @@ | ||
import { describe, test } from 'vitest'; | ||
import { z } from 'zod'; | ||
import { expect } from './utils/expect'; | ||
|
||
describe('Function', () => { | ||
test('base', () => { | ||
const schema = z.function(); | ||
|
||
expect(schema); | ||
}); | ||
test('with args as param', () => { | ||
const schema = z.function(z.tuple([z.string(), z.number()]), z.boolean()); | ||
|
||
expect(schema); | ||
}); | ||
test('with args as method', () => { | ||
const schema = z.function().args(z.string(), z.number()); | ||
|
||
expect(schema); | ||
}); | ||
test('with returns as param', () => { | ||
const schema = z.function(z.tuple([z.string(), z.number()]), z.boolean()); | ||
|
||
expect(schema); | ||
}); | ||
test('with returns as method', () => { | ||
const schema = z.function().returns(z.boolean()); | ||
|
||
expect(schema); | ||
}); | ||
}); |