timdeschryver / zod-fixture

Creating fixtures based on zod schemas
https://zod-fixture.timdeschryver.dev/
MIT License
121 stars 10 forks source link

Invalid values for nativeEnum #4

Closed ridem closed 2 years ago

ridem commented 2 years ago

Great library!

I've noticed that fixtures for nativeEnum can return the actual keys of the enum, which are invalid values as per the zod schema. Is there a reason for this? If it's a bug, happy to make a PR.

For example, I don't understand why "Apple", "Banana" and "Cantaloupe" are valid values here: https://github.com/timdeschryver/zod-fixture/blob/80d60351483dc26b9fb52e94ee2fe749c00fd7d6/test/create.test.ts#L427-L437

import { createFixture } from "zod-fixture";
import { z } from "zod";
const Fruits = {
  Apple: "apple",
  Banana: "banana",
  Cantaloupe: 3,
} as const;

const schema = z.nativeEnum(Fruits);
const fixture = createFixture(schema); // type is `"apple" | "banana" | 3`, but runtime value could be `"Apple"`
schema.parse(fixture); // This throws
timdeschryver commented 2 years ago

Oops 😅 you're right, this should only resolve to the values. Feel free to create a PR. Thanks for bringing this up!

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 1.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: