一覧へ戻る
ItMaga/zodock(新しいタブで開きます)
主要言語: TypeScript
A library for generating mock data based on Zod schemas
- star 数
- 14
- watcher 数
- 1
- fork 数
- 1
- issue 数
- 2
- 最終更新
- 2024/08/19
主要言語: TypeScript
A library for generating mock data based on Zod schemas
The mocking library for TypeScript-first schema validation Zod, creates a mock object based on the schema. It makes it easy to create mock data for testing purposes, to create mock data for the API request or response, and etc.
npm install -D zodock
import { createMock } from 'zodock'; const schema = z.object({ name: z.string(), age: z.number(), }); createMock(schema); // { name: string, age: number }
import { createMock } from 'zodock'; const schema = z.object({ name: z.string(), age: z.number(), }); describe('test', () => { const mockSchema = createMock(schema); const apiMock = jest.fn().mockResolvedValue(mockSchema); it('should return mock data', async () => { const result = await apiMock(); expect(result).toEqual(mockSchema); }); });
import { createMock } from 'zodock'; const schema = z.object({ name: z.string(), age: z.number(), }); const mockSchema = createMock(schema); export const api = { get: () => { return mockSchema; } };
or you can imitate axios response
import { createMock } from 'zodock'; const schema = z.object({ name: z.string(), age: z.number(), }); export const api = { get: () => { return new Promise(resolve => resolve({ status: 200, statusText: 'OK', headers: {}, data: createMock(schema), config: {}, }), ); } };
MIT License © 2023 Magomed Chemurziev