Skip to content

dependabit / test-utils/src / createMockArray

Function: createMockArray()

ts
function createMockArray<T>(count, factory): T[];

Defined in: packages/test-utils/src/fixtures.ts:104

Creates an array of mock items using a factory function.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
countnumberNumber of items to create.
factory(index) => TFunction called with each zero-based index to produce an item.

Returns

T[]

Array of count items.

Example

ts
const users = createMockArray(5, (i) => ({ id: i, name: `User${i}` }));
expect(users).toHaveLength(5);

Released under the MIT License.