Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OlivierCuyp opened this issue May 8, 2024 · 0 comments

Comments

@OlivierCuyp
Copy link
Contributor

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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant