diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0f4d21c0d57..ac01c8c2c28 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -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 }], }, }, diff --git a/test/modules/git.spec.ts b/test/modules/git.spec.ts index 8957e99566b..e4692b20477 100644 --- a/test/modules/git.spec.ts +++ b/test/modules/git.spec.ts @@ -134,7 +134,7 @@ describe('git', () => { expect(commitDate).toBeTypeOf('string'); const parts = commitDate.split(' '); - expect(parts.length).toBe(6); + expect(parts).toHaveLength(6); }); }); diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts index 98c3488a959..b9b59f22b95 100644 --- a/test/modules/helpers.spec.ts +++ b/test/modules/helpers.spec.ts @@ -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) { @@ -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', () => { @@ -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', () => { @@ -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]); }); }); diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts index 86897ad55e5..dc82757d29d 100644 --- a/test/modules/location.spec.ts +++ b/test/modules/location.spec.ts @@ -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', () => { @@ -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');