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
| Parameter | Type | Description |
|---|---|---|
count | number | Number of items to create. |
factory | (index) => T | Function 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);