-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
58 additions
and
0 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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
- ✅ z.record | ||
- ✅ z.set | ||
- ✅ z.string[^1] | ||
- ✅ z.symbol | ||
- ✅ z.tuple | ||
- ✅ z.undefined | ||
- ✅ z.union | ||
|
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,14 @@ | ||
import * as z from 'zod' | ||
import { ZodTypeFaker } from './zod-type-faker' | ||
|
||
export class ZodSymbolFaker<T extends z.ZodSymbol> extends ZodTypeFaker<T> { | ||
fake(): z.infer<T> { | ||
return Symbol() | ||
} | ||
|
||
static create<T extends z.ZodSymbol>(schema: T): ZodSymbolFaker<T> { | ||
return new ZodSymbolFaker(schema) | ||
} | ||
} | ||
|
||
export const zodSymbolFaker: typeof ZodSymbolFaker.create = ZodSymbolFaker.create |
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 { expect, test } from 'vitest' | ||
import * as z from 'zod' | ||
import { zodSymbolFaker, ZodSymbolFaker } from '../src/zod-symbol-faker' | ||
import { expectType, TypeEqual } from 'ts-expect' | ||
|
||
test('ZodSymbolFaker should assert parameters', () => { | ||
const invalidSchema = void 0 as any | ||
expect(() => zodSymbolFaker(invalidSchema)).toThrow() | ||
}) | ||
|
||
test('ZodSymbolFaker should accepts a ZodSymbol schema', () => { | ||
const schema = z.symbol() | ||
expect(() => zodSymbolFaker(schema)).not.toThrow() | ||
}) | ||
|
||
test('ZodSymbolFaker should return a ZodSymbolFaker instance', () => { | ||
expect(typeof zodSymbolFaker).toBe('function') | ||
|
||
const schema = z.symbol() | ||
const faker = zodSymbolFaker(schema) | ||
expect(faker instanceof ZodSymbolFaker).toBe(true) | ||
}) | ||
|
||
test('ZodSymbolFaker.fake should be a function', () => { | ||
const schema = z.symbol() | ||
const faker = zodSymbolFaker(schema) | ||
expect(typeof faker.fake).toBe('function') | ||
}) | ||
|
||
test('ZodSymbolFaker.fake should return the given type', () => { | ||
const schema = z.symbol() | ||
const faker = zodSymbolFaker(schema) | ||
expectType<TypeEqual<ReturnType<typeof faker.fake>, z.infer<typeof schema>>>(true) | ||
}) | ||
|
||
test('ZodSymbolFaker.fake should return a valid data', () => { | ||
const schema = z.symbol() | ||
const faker = zodSymbolFaker(schema) | ||
const data = faker.fake() | ||
expect(schema.safeParse(data).success).toBe(true) | ||
}) |