Skip to content

Commit

Permalink
chore: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Mar 24, 2022
1 parent 7811a75 commit 1a46b5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ export class Faker {

constructor(opts: FakerOptions) {
if (!opts) {
throw new Error('Options with at least one locale must be provided');
throw new Error(
'Options with at least one entry in locales must be provided'
);
}

if (Object.keys(opts.locales ?? {}).length === 0) {
throw new Error(
'At least one locale must be provided in the locales parameter'
'At least one entry in locales must be provided in the locales parameter'
);
}

Expand Down
8 changes: 6 additions & 2 deletions test/faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ describe('faker', () => {
() =>
// @ts-expect-error: mission options
new Faker()
).toThrow(Error('Options with at least one locale must be provided'));
).toThrow(
Error('Options with at least one entry in locales must be provided')
);
});

it('should throw error if no locales passed', () => {
Expand All @@ -20,7 +22,9 @@ describe('faker', () => {
// @ts-expect-error: missing locales
new Faker({})
).toThrow(
Error('At least one locale must be provided in the locales parameter')
Error(
'At least one entry in locales must be provided in the locales parameter'
)
);
});

Expand Down

0 comments on commit 1a46b5e

Please sign in to comment.