Skip to content
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
8 changes: 2 additions & 6 deletions eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ export default defineConfig(
{
name: 'test/**/*.ts overrides',
files: ['test/**/*.spec.ts', 'test/**/*.spec.cts', 'test/**/*.spec.d.ts'],
plugins: {
// @ts-expect-error: weird type error
vitest: eslintPluginVitest,
},
extends: [eslintPluginVitest.configs.recommended],
rules: {
'@typescript-eslint/no-deprecated': 'off',

Expand All @@ -271,10 +268,9 @@ export default defineConfig(
},
],

...eslintPluginVitest.configs.recommended.rules,

'vitest/expect-expect': 'off',
'vitest/no-alias-methods': 'error',
'vitest/no-conditional-expect': 'off', // we require conditional logic when iterating over faker instances or instances in diffent versions (for the docs)
'vitest/prefer-each': 'error',
'vitest/prefer-to-have-length': 'error',
'vitest/valid-expect': ['error', { maxArgs: 2 }],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@types/semver": "7.7.1",
"@types/validator": "13.15.10",
"@vitest/coverage-v8": "3.2.4",
"@vitest/eslint-plugin": "1.3.20",
"@vitest/eslint-plugin": "1.6.3",
"@vitest/ui": "3.2.4",
"@vueuse/core": "13.9.0",
"commit-and-tag-version": "12.6.1",
Expand Down
228 changes: 10 additions & 218 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ describe('faker', () => {
// Non-existing module
expect(faker.definitions.missing).toBeDefined();
// Non-existing definition in a non-existing module
expect(() => faker.definitions.missing?.missing).toThrow();
expect(() => faker.definitions.missing?.missing).toThrowError();
// Non-existing definition in an existing module
expect(() => faker.definitions.location.missing).toThrow();
expect(() => faker.definitions.location.missing).toThrowError();
});
});

describe('constructor()', () => {
describe('locale', () => {
it('should throw error if no locales passed', () => {
expect(() => new Faker({ locale: [] })).toThrow(
expect(() => new Faker({ locale: [] })).toThrowError(
new FakerError(
'The locale option must contain at least one locale definition.'
)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/modules/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { faker } from '../../../src';
async function assertWorkingUrl(address: string): Promise<void> {
expect(address).toBeTypeOf('string');
expect(address).toMatch(/^https:\/\//);
expect(() => new URL(address)).not.toThrow();
expect(() => new URL(address)).not.toThrowError();

await expect(
new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions test/internal/bind-this-to-member-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ describe('internal', () => {

const someMethodWithoutBind = someModule.someMethod;

expect(() => someMethodWithoutBind()).toThrow(
expect(() => someMethodWithoutBind()).toThrowError(
new TypeError("Cannot read properties of undefined (reading 'faker')")
);

bindThisToMemberFunctions(someModule);

const someMethod = someModule.someMethod;

expect(() => someMethod()).not.toThrow();
expect(() => someMethod()).not.toThrowError();
});
});
});
2 changes: 1 addition & 1 deletion test/internal/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('toDate()', () => {

it('should throw a FakerError for an invalid date string', () => {
const timestamp = 'aaaa-07-05T15:49:19+0000';
expect(() => toDate(timestamp)).toThrow(
expect(() => toDate(timestamp)).toThrowError(
new FakerError(`Invalid refDate date: ${timestamp}`)
);
});
Expand Down
26 changes: 13 additions & 13 deletions test/internal/locale-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
locale.category = {};
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -46,7 +46,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
locale.airline = {};
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -55,7 +55,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
delete locale.category;
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -64,7 +64,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
delete locale.airline;
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('LocaleProxy', () => {
});

it('should not be possible to access a missing entry in a missing category', () => {
expect(() => locale.category.missing).toThrow(
expect(() => locale.category.missing).toThrowError(
new FakerError(
`The locale data for 'category.missing' are missing in this locale.
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Expand All @@ -105,7 +105,7 @@ describe('LocaleProxy', () => {
});

it('should not be possible to access a missing entry in a present category', () => {
expect(() => locale.airline.missing).toThrow(
expect(() => locale.airline.missing).toThrowError(
new FakerError(
`The locale data for 'airline.missing' are missing in this locale.
If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Expand All @@ -124,7 +124,7 @@ describe('LocaleProxy', () => {
airline: { airline: null },
});

expect(() => unavailable.airline.airline).toThrow(
expect(() => unavailable.airline.airline).toThrowError(
new FakerError(
`The locale data for 'airline.airline' aren't applicable to this locale.
If you think this is a bug, please report it at: https://github.com/faker-js/faker`
Expand All @@ -136,7 +136,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
locale.category.missing = {};
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -145,7 +145,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
locale.airline.missing = {};
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -154,7 +154,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
locale.airline.airline = ['dummy'];
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -163,7 +163,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
delete locale.category.missing;
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -172,7 +172,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
delete locale.airline.missing;
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand All @@ -181,7 +181,7 @@ describe('LocaleProxy', () => {
expect(() => {
// @ts-expect-error: LocaleProxy is read-only.
delete locale.airline.airline;
}).toThrow(
}).toThrowError(
new FakerError('You cannot edit the locale data on the faker instance')
);
});
Expand Down
16 changes: 8 additions & 8 deletions test/modules/commerce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,39 +376,39 @@ describe('commerce', () => {
it('should throw FakerError when prefix contains non-digit characters', () => {
expect(() => {
faker.commerce.upc({ prefix: 'abc' });
}).toThrow('Prefix must contain only numeric digits');
}).toThrowError('Prefix must contain only numeric digits');

expect(() => {
faker.commerce.upc({ prefix: '123abc' });
}).toThrow('Prefix must contain only numeric digits');
}).toThrowError('Prefix must contain only numeric digits');

expect(() => {
faker.commerce.upc({ prefix: '12-34' });
}).toThrow('Prefix must contain only numeric digits');
}).toThrowError('Prefix must contain only numeric digits');

expect(() => {
faker.commerce.upc({ prefix: ' 123' });
}).toThrow('Prefix must contain only numeric digits');
}).toThrowError('Prefix must contain only numeric digits');
});

it('should throw FakerError when prefix is longer than 11 digits', () => {
expect(() => {
faker.commerce.upc({ prefix: '012345678901' });
}).toThrow('Prefix must be at most 11 numeric digits');
}).toThrowError('Prefix must be at most 11 numeric digits');

expect(() => {
faker.commerce.upc({ prefix: '012345678901234' });
}).toThrow('Prefix must be at most 11 numeric digits');
}).toThrowError('Prefix must be at most 11 numeric digits');
});

it('should throw FakerError with correct error message for invalid prefix types', () => {
expect(() => {
faker.commerce.upc({ prefix: '12a' });
}).toThrow('Prefix must contain only numeric digits');
}).toThrowError('Prefix must contain only numeric digits');

expect(() => {
faker.commerce.upc({ prefix: '012345678901' });
}).toThrow('Prefix must be at most 11 numeric digits');
}).toThrowError('Prefix must be at most 11 numeric digits');
});

it('should generate valid UPCs that pass check digit validation for multiple calls', () => {
Expand Down
6 changes: 4 additions & 2 deletions test/modules/datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ describe('datatype', () => {
const filledOptions: { probability?: number } = Object.freeze({
probability: 1,
});
expect(() => faker.datatype.boolean(filledOptions)).not.toThrow();
expect(() =>
faker.datatype.boolean(filledOptions)
).not.toThrowError();

const emptyOptions: { probability?: number } = Object.freeze({});
expect(() => faker.datatype.boolean(emptyOptions)).not.toThrow();
expect(() => faker.datatype.boolean(emptyOptions)).not.toThrowError();
});
});
}
Expand Down
26 changes: 15 additions & 11 deletions test/modules/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('date', () => {
it.each(['invalid', Number.NaN, new Date(Number.NaN)] as const)(
'should reject invalid refDates %s',
(refDate) => {
expect(() => faker.date[method]({ refDate })).toThrow(
expect(() => faker.date[method]({ refDate })).toThrowError(
new FakerError(`Invalid refDate date: ${refDate.toString()}`)
);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('date', () => {
const refDate = new Date();
expect(() =>
faker.date.past({ years: 0, refDate: refDate.toISOString() })
).toThrow(new FakerError('Years must be greater than 0.'));
).toThrowError(new FakerError('Years must be greater than 0.'));
});

it.each(converterMap)(
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('date', () => {
const refDate = new Date();
expect(() =>
faker.date.future({ years: 0, refDate: refDate.toISOString() })
).toThrow(new FakerError('Years must be greater than 0.'));
).toThrowError(new FakerError('Years must be greater than 0.'));
});

it.each(converterMap)(
Expand Down Expand Up @@ -268,7 +268,9 @@ describe('date', () => {
from: '2000-01-01',
to: '1990-01-01',
})
).toThrow(new FakerError('`from` date must be before `to` date.'));
).toThrowError(
new FakerError('`from` date must be before `to` date.')
);
});

it('should allow date 0 (start of UNIX epoch)', () => {
Expand All @@ -285,7 +287,7 @@ describe('date', () => {
from: '1990-01-01',
to: 'not-a-date',
})
).toThrow(new FakerError('Invalid to date: not-a-date'));
).toThrowError(new FakerError('Invalid to date: not-a-date'));
});
});

Expand Down Expand Up @@ -364,7 +366,9 @@ describe('date', () => {
to: '1990-01-01',
count: 3,
})
).toThrow(new FakerError('`from` date must be before `to` date.'));
).toThrowError(
new FakerError('`from` date must be before `to` date.')
);
});

it('should throw an error if to is invalid', () => {
Expand All @@ -374,7 +378,7 @@ describe('date', () => {
to: 'not-a-date',
count: 3,
})
).toThrow(new FakerError('Invalid to date: not-a-date'));
).toThrowError(new FakerError('Invalid to date: not-a-date'));
});
});

Expand All @@ -389,7 +393,7 @@ describe('date', () => {
const refDate = new Date();
expect(() =>
faker.date.recent({ days: 0, refDate: refDate.toISOString() })
).toThrow(new FakerError('Days must be greater than 0.'));
).toThrowError(new FakerError('Days must be greater than 0.'));
});

it.each(converterMap)(
Expand Down Expand Up @@ -430,7 +434,7 @@ describe('date', () => {
const refDate = new Date();
expect(() =>
faker.date.soon({ days: 0, refDate: refDate.toISOString() })
).toThrow(new FakerError('Days must be greater than 0.'));
).toThrowError(new FakerError('Days must be greater than 0.'));
});

it.each(converterMap)(
Expand Down Expand Up @@ -618,7 +622,7 @@ describe('date', () => {

expect(() =>
faker.date.birthdate({ min, max, mode: 'year' })
).toThrow(
).toThrowError(
new FakerError(
`Max year 1990 should be greater than or equal to min year 2000.`
)
Expand All @@ -632,7 +636,7 @@ describe('date', () => {

expect(() =>
faker.date.birthdate({ min, max, refDate, mode: 'age' })
).toThrow(
).toThrowError(
new FakerError(
`Max age 25 should be greater than or equal to min age 31.`
)
Expand Down
Loading
Loading