aboutsummaryrefslogtreecommitdiff
path: root/test/modules
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-11-14 17:11:26 +0100
committerGitHub <[email protected]>2023-11-14 16:11:26 +0000
commit7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1 (patch)
treebb6813a857c0c42ba1049be5035fce7f45b99c46 /test/modules
parent36fc517d17591c8ea1d5135d9a93c7591e3d1f74 (diff)
downloadfaker-7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1.tar.xz
faker-7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1.zip
infra: enable strictNullChecks in tsconfig (#2435)
Diffstat (limited to 'test/modules')
-rw-r--r--test/modules/airline.spec.ts12
-rw-r--r--test/modules/finance-iban.spec.ts13
-rw-r--r--test/modules/helpers.spec.ts3
3 files changed, 16 insertions, 12 deletions
diff --git a/test/modules/airline.spec.ts b/test/modules/airline.spec.ts
index 5ac05a5b..bf674570 100644
--- a/test/modules/airline.spec.ts
+++ b/test/modules/airline.spec.ts
@@ -96,7 +96,7 @@ describe('airline', () => {
it('should return a random narrowbody seat when not passing an argument', () => {
const seat = faker.airline.seat();
const matchResult = seatRegex.exec(seat);
- expect(matchResult).not.toBeNull();
+ expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 35);
@@ -107,7 +107,7 @@ describe('airline', () => {
aircraftType: Aircraft.Narrowbody,
});
const matchResult = seatRegex.exec(seat);
- expect(matchResult).not.toBeNull();
+ expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 35);
@@ -116,7 +116,7 @@ describe('airline', () => {
it('should return a random regional seat', () => {
const seat = faker.airline.seat({ aircraftType: Aircraft.Regional });
const matchResult = seatRegex.exec(seat);
- expect(matchResult).not.toBeNull();
+ expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 20);
@@ -125,7 +125,7 @@ describe('airline', () => {
it('should return a random widebody seat', () => {
const seat = faker.airline.seat({ aircraftType: Aircraft.Widebody });
const matchResult = seatRegex.exec(seat);
- expect(matchResult).not.toBeNull();
+ expectNotNull(matchResult);
const row = matchResult[1];
const seatLetter = matchResult[2];
expect(row).toSatisfy((row: number) => row >= 1 && row <= 60);
@@ -179,3 +179,7 @@ describe('airline', () => {
}
);
});
+
+function expectNotNull<T>(value: T): asserts value is NonNullable<T> {
+ expect(value).not.toBeNull();
+}
diff --git a/test/modules/finance-iban.spec.ts b/test/modules/finance-iban.spec.ts
index 145a4751..4d801aa5 100644
--- a/test/modules/finance-iban.spec.ts
+++ b/test/modules/finance-iban.spec.ts
@@ -1,6 +1,7 @@
import validator from 'validator';
import { describe, expect, it } from 'vitest';
import { faker } from '../../src';
+import { prettyPrintIban } from '../../src/modules/finance';
import ibanLib from '../../src/modules/finance/iban';
import { times } from '../support/times';
@@ -36,7 +37,7 @@ describe('finance_iban', () => {
expect(iban).toSatisfy(validator.isIBAN);
- const ibanFormatted = iban.match(/.{1,4}/g).join(' ');
+ const ibanFormatted = prettyPrintIban(iban);
const bban = iban.substring(4) + iban.substring(0, 4);
expect(
@@ -96,7 +97,7 @@ describe('finance_iban', () => {
expect(iban).toSatisfy(validator.isIBAN);
- const ibanFormated = iban.match(/.{1,4}/g).join(' ');
+ const ibanFormated = prettyPrintIban(iban);
const bban = iban.substring(4) + iban.substring(0, 4);
expect(
@@ -162,7 +163,7 @@ describe('finance_iban', () => {
expect(iban).toSatisfy(validator.isIBAN);
- const ibanFormated = iban.match(/.{1,4}/g).join(' ');
+ const ibanFormated = prettyPrintIban(iban);
const bban = iban.substring(4) + iban.substring(0, 4);
expect(
@@ -232,7 +233,7 @@ describe('finance_iban', () => {
expect(iban).toSatisfy(validator.isIBAN);
- const ibanFormated = iban.match(/.{1,4}/g).join(' ');
+ const ibanFormated = prettyPrintIban(iban);
const bban = iban.substring(4) + iban.substring(0, 4);
expect(
@@ -291,7 +292,7 @@ describe('finance_iban', () => {
expect(iban).toSatisfy(validator.isIBAN);
- const ibanFormated = iban.match(/.{1,4}/g).join(' ');
+ const ibanFormated = prettyPrintIban(iban);
const bban = iban.substring(4) + iban.substring(0, 4);
expect(
@@ -336,7 +337,7 @@ describe('finance_iban', () => {
// Bank account number 16 digit
const iban = faker.finance.iban(false, 'AL');
- const ibanFormated = iban.match(/.{1,4}/g).join(' ');
+ const ibanFormated = prettyPrintIban(iban);
expect(iban).toSatisfy(validator.isIBAN);
diff --git a/test/modules/helpers.spec.ts b/test/modules/helpers.spec.ts
index 3f850086..766d0650 100644
--- a/test/modules/helpers.spec.ts
+++ b/test/modules/helpers.spec.ts
@@ -223,7 +223,6 @@ describe('helpers', () => {
});
it('should throw on an empty array', () => {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
expect(() => faker.helpers.arrayElement([])).toThrow(
new FakerError('Cannot get value from empty dataset.')
);
@@ -1062,7 +1061,7 @@ describe('helpers', () => {
});
it('should be able to return locale definition strings', () => {
- expect(faker.definitions.cell_phone.formats).toContain(
+ expect(faker.definitions.cell_phone?.formats).toContain(
faker.helpers.fake('{{cell_phone.formats}}')
);
});