-
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
39 additions
and
5 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
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 { ZodReadonly, ZodTypeAny } from 'zod'; | ||
import MockGenerator from '../MockGenerator'; | ||
import type BaseGenerator from './BaseGenerator'; | ||
|
||
export default class ReadonlyGenerator<T extends ZodTypeAny, U extends ZodReadonly<T>> implements BaseGenerator<U> { | ||
public generate(schema: U) { | ||
const mockGenerator = new MockGenerator(schema._def.innerType); | ||
return Object.freeze(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, test } from 'vitest'; | ||
import { z } from 'zod'; | ||
import { expect } from './utils/expect'; | ||
|
||
describe('Readonly', () => { | ||
test('base', () => { | ||
const object = z.object({ foo: z.string(), bar: z.number() }).readonly(); | ||
expect(object); | ||
|
||
const array = z.array(z.string()).readonly(); | ||
expect(array); | ||
|
||
const string = z.string().readonly(); | ||
expect(string); | ||
|
||
const number = z.number().readonly(); | ||
expect(number); | ||
|
||
const boolean = z.boolean().readonly(); | ||
expect(boolean); | ||
}); | ||
}); |
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