Skip to content

Commit

Permalink
infra(vitest): prefer-to-have-length (#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored May 14, 2024
1 parent 044a756 commit 7fb9bb5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ module.exports = defineConfig({

'vitest/expect-expect': 'off',
'vitest/prefer-each': 'error',
'vitest/prefer-to-have-length': 'error',
'vitest/valid-expect': ['error', { maxArgs: 2 }],
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/modules/git.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('git', () => {
expect(commitDate).toBeTypeOf('string');

const parts = commitDate.split(' ');
expect(parts.length).toBe(6);
expect(parts).toHaveLength(6);
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/modules/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe('helpers', () => {
const subset = faker.helpers.arrayElements(testArray, 6);

// Check length
expect(subset.length).toBe(5);
expect(subset).toHaveLength(5);

// Check elements
for (const element of subset) {
Expand Down Expand Up @@ -1078,7 +1078,7 @@ describe('helpers', () => {
const result = faker.helpers.multiple(() => faker.person.firstName());
expect(result).toBeTypeOf('object');
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(3);
expect(result).toHaveLength(3);
});

it('should generate the given amount of values from the function', () => {
Expand All @@ -1090,7 +1090,7 @@ describe('helpers', () => {
);
expect(result).toBeTypeOf('object');
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(5);
expect(result).toHaveLength(5);
});

it('should generate a ranged number of values from the function', () => {
Expand All @@ -1112,7 +1112,7 @@ describe('helpers', () => {
});
expect(result).toBeTypeOf('object');
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(3);
expect(result).toHaveLength(3);
expect(result).toStrictEqual([0, 2, 4]);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/modules/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('location', () => {

it('should return a zip code with length 5 for ZIP codes that start with 0', () => {
const zipCode = fakerEN_US.location.zipCode({ state: 'NH' });
expect(zipCode.length).toBe(5);
expect(zipCode).toHaveLength(5);
});

it('should throw when definitions.location.postcode_by_state not set', () => {
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('location', () => {
isMetric,
});

expect(coordinate.length).toBe(2);
expect(coordinate).toHaveLength(2);
expect(coordinate[0]).toBeTypeOf('number');
expect(coordinate[1]).toBeTypeOf('number');

Expand Down

0 comments on commit 7fb9bb5

Please sign in to comment.