From 100a1ea230cba422174a6b5103c56bc4cf9c0dc4 Mon Sep 17 00:00:00 2001 From: c0per <60544162+c0per@users.noreply.github.com> Date: Wed, 4 May 2022 17:30:58 +0800 Subject: fix: empty array passed into helpers.arrayElements (#921) --- src/modules/helpers/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 1b28ddfa..7f056b9f 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -783,7 +783,10 @@ export class Helpers { count?: number ): T[] { if (typeof count !== 'number') { - count = this.faker.datatype.number({ min: 1, max: array.length }); + count = + array.length === 0 + ? 0 + : this.faker.datatype.number({ min: 1, max: array.length }); } else if (count > array.length) { count = array.length; } else if (count < 0) { -- cgit v1.2.3