anatine / zod-plugins

Plugins and utilities for Zod
591 stars 84 forks source link

[zod-mock] z.string().min(x) gives "RangeError: Invalid array length" (randomly) #203

Open OlivierCuyp opened 1 month ago

OlivierCuyp commented 1 month ago

versions used:

"@anatine/zod-mock": "3.13.4"
"zod": "3.23.4"
"@faker-js/faker": "8.4.1"

I have an error sometimes error with this example:

./test.ts:

import { generateMock } from '@anatine/zod-mock';
import z from 'zod';

const testSchema = z.object({
  passwordHash: z.string().min(8)
});

const fakeData = generateMock(testSchema);

console.log(fakeData);

shell outputs:

❯ npx ts-node ./test.ts
{ passwordHash: 'crepusculum' }

❯ npx ts-node ./src/test.ts
RangeError: Invalid array length
    at Function.from (<anonymous>)
    at ee.multiple (/test/node_modules/@faker-js/faker/dist/cjs/modules/helpers/index.js:1:8233)
    at A.fromCharacters (/test/node_modules/@faker-js/faker/dist/cjs/modules/string/index.js:1:929)
    at A.alpha (/test/node_modules/@faker-js/faker/dist/cjs/modules/string/index.js:1:1361)
    at Object.parseString [as ZodString] (/test/packages/zod-mock/src/lib/zod-mock.ts:260:38)
    at generateMock (/test/packages/zod-mock/src/lib/zod-mock.ts:603:33)
    at /test/packages/zod-mock/src/lib/zod-mock.ts:27:14
    at Array.reduce (<anonymous>)
    at Object.parseObject [as ZodObject] (/test/packages/zod-mock/src/lib/zod-mock.ts:24:36)
    at generateMock (/test/packages/zod-mock/src/lib/zod-mock.ts:603:33)
{ passwordHash: undefined }