Zod, mocking fake data that works with refine?

Does anyone have some experience with zod mocking libaries? Docs list like six of them but my most important feature would be to get it working with refine(). I understand it's not possible to automate refine(), but I need it to get that working without huge hassle.
4 Replies
Sturlen
Sturlen2y ago
what exactly is it you're trying to do? is to generate fake data based on a zod schema?
Massukka
MassukkaOP2y ago
Yes
Froxx
Froxx2y ago
What I do is defining a generate function for each model using faker for data population like so:
import { z } from "zod";
import { faker } from "@faker-js/faker";

const Person = z.object({
firstName: z.string(),
lastName: z.string(),
});

export const generatePerson = (): z.infer<typeof Person> => {
return {
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
};
};
import { z } from "zod";
import { faker } from "@faker-js/faker";

const Person = z.object({
firstName: z.string(),
lastName: z.string(),
});

export const generatePerson = (): z.infer<typeof Person> => {
return {
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
};
};
Massukka
MassukkaOP2y ago
Seems like it's best to just do it manually like you said with faker.
Want results from more Discord servers?
Add your server