Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Mar 1, 2024
1 parent 33a7e44 commit 1d53c6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ export class SimpleHelpersModule extends SimpleModuleBase {
* @example
* faker.helpers.multiple(faker.person.firstName) // [ 'Aniya', 'Norval', 'Dallin' ]
* faker.helpers.multiple(faker.person.firstName, { count: 3 }) // [ 'Santos', 'Lavinia', 'Lavinia' ]
* faker.helpers.multiple((_el, i) => `Person ${i + 1}` ) // [ 'Person 1', 'Person 2', 'Person 3' ]
* faker.helpers.multiple((_, i) => `Person ${i + 1}` ) // [ 'Person 1', 'Person 2', 'Person 3' ]
*
* @since 8.0.0
*/
Expand Down
28 changes: 18 additions & 10 deletions test/modules/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ describe('helpers', () => {
});

t.describe('multiple', (t) => {
t.it('with only method', faker.datatype.number)
.it('with method and count', faker.datatype.number, { count: 5 })
.it('with method and count range', faker.datatype.number, {
t.it('with only method', () => faker.datatype.number())
.it('with method and count', () => faker.datatype.number(), {
count: 5,
})
.it('with method and count range', () => faker.datatype.number(), {
count: { min: 1, max: 10 },
})
.it('with method using index', (_el, i) => i * 3);
Expand Down Expand Up @@ -1227,25 +1229,31 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`)

describe('multiple()', () => {
it('should generate values from the function with a default length of 3', () => {
const result = faker.helpers.multiple(faker.person.firstName);
const result = faker.helpers.multiple(() => faker.person.firstName());
expect(result).toBeTypeOf('object');
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(3);
});

it('should generate the given amount of values from the function', () => {
const result = faker.helpers.multiple(faker.person.firstName, {
count: 5,
});
const result = faker.helpers.multiple(
() => faker.person.firstName(),
{
count: 5,
}
);
expect(result).toBeTypeOf('object');
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(5);
});

it('should generate a ranged number of values from the function', () => {
const result = faker.helpers.multiple(faker.person.firstName, {
count: { min: 1, max: 10 },
});
const result = faker.helpers.multiple(
() => faker.person.firstName(),
{
count: { min: 1, max: 10 },
}
);
expect(result).toBeTypeOf('object');
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBeGreaterThanOrEqual(1);
Expand Down

0 comments on commit 1d53c6a

Please sign in to comment.