Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra(vitest): prefer-to-have-length #2900

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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