From 3dece0904933f9632afabdacd0f2b5b32d8bde2a Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Thu, 27 Jul 2023 12:16:21 -0400 Subject: fix(helpers): prevent uniqueArray from hanging (#2239) --- test/helpers.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 67a2de3d..c7003dc8 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -806,6 +806,14 @@ describe('helpers', () => { expect(unique).toHaveLength(input.length); }); + it('function with length longer than possible values returns', () => { + const fn = () => faker.helpers.arrayElement(['a', 'b']); + const length = 3; + const unique = faker.helpers.uniqueArray(fn, length); + expect(unique).not.toContainDuplicates(); + expect(unique).toHaveLength(2); + }); + it('works as expected when seeded', () => { const input = ['a', 'a', 'a', 'a', 'a', 'f', 'g', 'h', 'i', 'j']; const length = 5; -- cgit v1.2.3