Skip to content

Commit c75363b

Browse files
chore: autofix lint errors
This commit fixes the autofixable lint errors introduced through the vitest lint plugin update. This mostly reverts the changes introduced in #2098, where .toThrowError was replaced by .toThrow. Apprently, the plugin got it the wrong way around. For more information, look at the fixing PR in their plugin: vitest-dev/eslint-plugin-vitest#832
1 parent fb271d4 commit c75363b

17 files changed

+145
-123
lines changed

test/faker.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ describe('faker', () => {
5555
// Non-existing module
5656
expect(faker.definitions.missing).toBeDefined();
5757
// Non-existing definition in a non-existing module
58-
expect(() => faker.definitions.missing?.missing).toThrow();
58+
expect(() => faker.definitions.missing?.missing).toThrowError();
5959
// Non-existing definition in an existing module
60-
expect(() => faker.definitions.location.missing).toThrow();
60+
expect(() => faker.definitions.location.missing).toThrowError();
6161
});
6262
});
6363

6464
describe('constructor()', () => {
6565
describe('locale', () => {
6666
it('should throw error if no locales passed', () => {
67-
expect(() => new Faker({ locale: [] })).toThrow(
67+
expect(() => new Faker({ locale: [] })).toThrowError(
6868
new FakerError(
6969
'The locale option must contain at least one locale definition.'
7070
)

test/integration/modules/image.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { faker } from '../../../src';
2323
async function assertWorkingUrl(address: string): Promise<void> {
2424
expect(address).toBeTypeOf('string');
2525
expect(address).toMatch(/^https:\/\//);
26-
expect(() => new URL(address)).not.toThrow();
26+
expect(() => new URL(address)).not.toThrowError();
2727

2828
await expect(
2929
new Promise((resolve, reject) => {

test/internal/bind-this-to-member-functions.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ describe('internal', () => {
1818

1919
const someMethodWithoutBind = someModule.someMethod;
2020

21-
expect(() => someMethodWithoutBind()).toThrow(
21+
expect(() => someMethodWithoutBind()).toThrowError(
2222
new TypeError("Cannot read properties of undefined (reading 'faker')")
2323
);
2424

2525
bindThisToMemberFunctions(someModule);
2626

2727
const someMethod = someModule.someMethod;
2828

29-
expect(() => someMethod()).not.toThrow();
29+
expect(() => someMethod()).not.toThrowError();
3030
});
3131
});
3232
});

test/internal/date.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('toDate()', () => {
1515

1616
it('should throw a FakerError for an invalid date string', () => {
1717
const timestamp = 'aaaa-07-05T15:49:19+0000';
18-
expect(() => toDate(timestamp)).toThrow(
18+
expect(() => toDate(timestamp)).toThrowError(
1919
new FakerError(`Invalid refDate date: ${timestamp}`)
2020
);
2121
});

test/internal/locale-proxy.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('LocaleProxy', () => {
3737
expect(() => {
3838
// @ts-expect-error: LocaleProxy is read-only.
3939
locale.category = {};
40-
}).toThrow(
40+
}).toThrowError(
4141
new FakerError('You cannot edit the locale data on the faker instance')
4242
);
4343
});
@@ -46,7 +46,7 @@ describe('LocaleProxy', () => {
4646
expect(() => {
4747
// @ts-expect-error: LocaleProxy is read-only.
4848
locale.airline = {};
49-
}).toThrow(
49+
}).toThrowError(
5050
new FakerError('You cannot edit the locale data on the faker instance')
5151
);
5252
});
@@ -55,7 +55,7 @@ describe('LocaleProxy', () => {
5555
expect(() => {
5656
// @ts-expect-error: LocaleProxy is read-only.
5757
delete locale.category;
58-
}).toThrow(
58+
}).toThrowError(
5959
new FakerError('You cannot edit the locale data on the faker instance')
6060
);
6161
});
@@ -64,7 +64,7 @@ describe('LocaleProxy', () => {
6464
expect(() => {
6565
// @ts-expect-error: LocaleProxy is read-only.
6666
delete locale.airline;
67-
}).toThrow(
67+
}).toThrowError(
6868
new FakerError('You cannot edit the locale data on the faker instance')
6969
);
7070
});
@@ -94,7 +94,7 @@ describe('LocaleProxy', () => {
9494
});
9595

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

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

127-
expect(() => unavailable.airline.airline).toThrow(
127+
expect(() => unavailable.airline.airline).toThrowError(
128128
new FakerError(
129129
`The locale data for 'airline.airline' aren't applicable to this locale.
130130
If you think this is a bug, please report it at: https://github.com/faker-js/faker`
@@ -136,7 +136,7 @@ describe('LocaleProxy', () => {
136136
expect(() => {
137137
// @ts-expect-error: LocaleProxy is read-only.
138138
locale.category.missing = {};
139-
}).toThrow(
139+
}).toThrowError(
140140
new FakerError('You cannot edit the locale data on the faker instance')
141141
);
142142
});
@@ -145,7 +145,7 @@ describe('LocaleProxy', () => {
145145
expect(() => {
146146
// @ts-expect-error: LocaleProxy is read-only.
147147
locale.airline.missing = {};
148-
}).toThrow(
148+
}).toThrowError(
149149
new FakerError('You cannot edit the locale data on the faker instance')
150150
);
151151
});
@@ -154,7 +154,7 @@ describe('LocaleProxy', () => {
154154
expect(() => {
155155
// @ts-expect-error: LocaleProxy is read-only.
156156
locale.airline.airline = ['dummy'];
157-
}).toThrow(
157+
}).toThrowError(
158158
new FakerError('You cannot edit the locale data on the faker instance')
159159
);
160160
});
@@ -163,7 +163,7 @@ describe('LocaleProxy', () => {
163163
expect(() => {
164164
// @ts-expect-error: LocaleProxy is read-only.
165165
delete locale.category.missing;
166-
}).toThrow(
166+
}).toThrowError(
167167
new FakerError('You cannot edit the locale data on the faker instance')
168168
);
169169
});
@@ -172,7 +172,7 @@ describe('LocaleProxy', () => {
172172
expect(() => {
173173
// @ts-expect-error: LocaleProxy is read-only.
174174
delete locale.airline.missing;
175-
}).toThrow(
175+
}).toThrowError(
176176
new FakerError('You cannot edit the locale data on the faker instance')
177177
);
178178
});
@@ -181,7 +181,7 @@ describe('LocaleProxy', () => {
181181
expect(() => {
182182
// @ts-expect-error: LocaleProxy is read-only.
183183
delete locale.airline.airline;
184-
}).toThrow(
184+
}).toThrowError(
185185
new FakerError('You cannot edit the locale data on the faker instance')
186186
);
187187
});

test/modules/commerce.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,39 +376,39 @@ describe('commerce', () => {
376376
it('should throw FakerError when prefix contains non-digit characters', () => {
377377
expect(() => {
378378
faker.commerce.upc({ prefix: 'abc' });
379-
}).toThrow('Prefix must contain only numeric digits');
379+
}).toThrowError('Prefix must contain only numeric digits');
380380

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

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

389389
expect(() => {
390390
faker.commerce.upc({ prefix: ' 123' });
391-
}).toThrow('Prefix must contain only numeric digits');
391+
}).toThrowError('Prefix must contain only numeric digits');
392392
});
393393

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

399399
expect(() => {
400400
faker.commerce.upc({ prefix: '012345678901234' });
401-
}).toThrow('Prefix must be at most 11 numeric digits');
401+
}).toThrowError('Prefix must be at most 11 numeric digits');
402402
});
403403

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

409409
expect(() => {
410410
faker.commerce.upc({ prefix: '012345678901' });
411-
}).toThrow('Prefix must be at most 11 numeric digits');
411+
}).toThrowError('Prefix must be at most 11 numeric digits');
412412
});
413413

414414
it('should generate valid UPCs that pass check digit validation for multiple calls', () => {

test/modules/datatype.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ describe('datatype', () => {
6868
const filledOptions: { probability?: number } = Object.freeze({
6969
probability: 1,
7070
});
71-
expect(() => faker.datatype.boolean(filledOptions)).not.toThrow();
71+
expect(() =>
72+
faker.datatype.boolean(filledOptions)
73+
).not.toThrowError();
7274

7375
const emptyOptions: { probability?: number } = Object.freeze({});
74-
expect(() => faker.datatype.boolean(emptyOptions)).not.toThrow();
76+
expect(() => faker.datatype.boolean(emptyOptions)).not.toThrowError();
7577
});
7678
});
7779
}

test/modules/date.spec.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('date', () => {
161161
it.each(['invalid', Number.NaN, new Date(Number.NaN)] as const)(
162162
'should reject invalid refDates %s',
163163
(refDate) => {
164-
expect(() => faker.date[method]({ refDate })).toThrow(
164+
expect(() => faker.date[method]({ refDate })).toThrowError(
165165
new FakerError(`Invalid refDate date: ${refDate.toString()}`)
166166
);
167167
}
@@ -194,7 +194,7 @@ describe('date', () => {
194194
const refDate = new Date();
195195
expect(() =>
196196
faker.date.past({ years: 0, refDate: refDate.toISOString() })
197-
).toThrow(new FakerError('Years must be greater than 0.'));
197+
).toThrowError(new FakerError('Years must be greater than 0.'));
198198
});
199199

200200
it.each(converterMap)(
@@ -225,7 +225,7 @@ describe('date', () => {
225225
const refDate = new Date();
226226
expect(() =>
227227
faker.date.future({ years: 0, refDate: refDate.toISOString() })
228-
).toThrow(new FakerError('Years must be greater than 0.'));
228+
).toThrowError(new FakerError('Years must be greater than 0.'));
229229
});
230230

231231
it.each(converterMap)(
@@ -268,7 +268,9 @@ describe('date', () => {
268268
from: '2000-01-01',
269269
to: '1990-01-01',
270270
})
271-
).toThrow(new FakerError('`from` date must be before `to` date.'));
271+
).toThrowError(
272+
new FakerError('`from` date must be before `to` date.')
273+
);
272274
});
273275

274276
it('should allow date 0 (start of UNIX epoch)', () => {
@@ -285,7 +287,7 @@ describe('date', () => {
285287
from: '1990-01-01',
286288
to: 'not-a-date',
287289
})
288-
).toThrow(new FakerError('Invalid to date: not-a-date'));
290+
).toThrowError(new FakerError('Invalid to date: not-a-date'));
289291
});
290292
});
291293

@@ -364,7 +366,9 @@ describe('date', () => {
364366
to: '1990-01-01',
365367
count: 3,
366368
})
367-
).toThrow(new FakerError('`from` date must be before `to` date.'));
369+
).toThrowError(
370+
new FakerError('`from` date must be before `to` date.')
371+
);
368372
});
369373

370374
it('should throw an error if to is invalid', () => {
@@ -374,7 +378,7 @@ describe('date', () => {
374378
to: 'not-a-date',
375379
count: 3,
376380
})
377-
).toThrow(new FakerError('Invalid to date: not-a-date'));
381+
).toThrowError(new FakerError('Invalid to date: not-a-date'));
378382
});
379383
});
380384

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

395399
it.each(converterMap)(
@@ -430,7 +434,7 @@ describe('date', () => {
430434
const refDate = new Date();
431435
expect(() =>
432436
faker.date.soon({ days: 0, refDate: refDate.toISOString() })
433-
).toThrow(new FakerError('Days must be greater than 0.'));
437+
).toThrowError(new FakerError('Days must be greater than 0.'));
434438
});
435439

436440
it.each(converterMap)(
@@ -618,7 +622,7 @@ describe('date', () => {
618622

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

633637
expect(() =>
634638
faker.date.birthdate({ min, max, refDate, mode: 'age' })
635-
).toThrow(
639+
).toThrowError(
636640
new FakerError(
637641
`Max age 25 should be greater than or equal to min age 31.`
638642
)

test/modules/finance.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ describe('finance', () => {
516516
});
517517

518518
it('should throw an error when length is less than 1', () => {
519-
expect(() => faker.finance.pin(-5)).toThrow(/^minimum length is 1$/);
519+
expect(() => faker.finance.pin(-5)).toThrowError(
520+
/^minimum length is 1$/
521+
);
520522
});
521523
});
522524

@@ -563,7 +565,7 @@ describe('finance', () => {
563565
formatted: false,
564566
countryCode: unsupportedCountryCode,
565567
})
566-
).toThrow(
568+
).toThrowError(
567569
new FakerError(
568570
`Country code ${unsupportedCountryCode} not supported.`
569571
)

0 commit comments

Comments
 (0)