Skip to content

Commit bfa7946

Browse files
authored
test: use toBeTypeOf (#511)
1 parent 2448aab commit bfa7946

19 files changed

Lines changed: 172 additions & 172 deletions

test/address.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ describe('address', () => {
398398
for (let i = 0; i < 100; i++) {
399399
const latitude = faker.address.latitude();
400400

401-
expect(typeof latitude).toBe('string');
401+
expect(latitude).toBeTypeOf('string');
402402

403403
const latitude_float = parseFloat(latitude);
404404

@@ -411,7 +411,7 @@ describe('address', () => {
411411
for (let i = 0; i < 100; i++) {
412412
const latitude = faker.address.latitude(-5, 5);
413413

414-
expect(typeof latitude).toBe('string');
414+
expect(latitude).toBeTypeOf('string');
415415
expect(
416416
latitude.split('.')[1].length,
417417
'The precision of latitude should be 4 digits'
@@ -428,7 +428,7 @@ describe('address', () => {
428428
for (let i = 0; i < 100; i++) {
429429
const latitude = faker.address.latitude(undefined, undefined, 7);
430430

431-
expect(typeof latitude).toBe('string');
431+
expect(latitude).toBeTypeOf('string');
432432
expect(
433433
latitude.split('.')[1].length,
434434
'The precision of latitude should be 7 digits'
@@ -447,7 +447,7 @@ describe('address', () => {
447447
for (let i = 0; i < 100; i++) {
448448
const longitude = faker.address.longitude();
449449

450-
expect(typeof longitude).toBe('string');
450+
expect(longitude).toBeTypeOf('string');
451451

452452
const longitude_float = parseFloat(longitude);
453453

@@ -460,7 +460,7 @@ describe('address', () => {
460460
for (let i = 0; i < 100; i++) {
461461
const longitude = faker.address.longitude(100, -30);
462462

463-
expect(typeof longitude).toBe('string');
463+
expect(longitude).toBeTypeOf('string');
464464
expect(
465465
longitude.split('.')[1].length,
466466
'The precision of longitude should be 4 digits'
@@ -477,7 +477,7 @@ describe('address', () => {
477477
for (let i = 0; i < 100; i++) {
478478
const longitude = faker.address.longitude(undefined, undefined, 7);
479479

480-
expect(typeof longitude).toBe('string');
480+
expect(longitude).toBeTypeOf('string');
481481
expect(
482482
longitude.split('.')[1].length,
483483
'The precision of longitude should be 7 digits'
@@ -499,9 +499,9 @@ describe('address', () => {
499499
'The abbreviation of direction when useAbbr is true should';
500500

501501
expect(
502-
typeof direction,
502+
direction,
503503
`${prefixErrorMessage} be of type string. Current is ${typeof direction}`
504-
).toBe('string');
504+
).toBeTypeOf('string');
505505
expect(lengthDirection).lessThanOrEqual(2);
506506
});
507507
});
@@ -515,9 +515,9 @@ describe('address', () => {
515515
'The ordinal direction when useAbbr is true should';
516516

517517
expect(
518-
typeof ordinalDirection,
518+
ordinalDirection,
519519
`${prefixErrorMessage} be equal ${expectedType}. Current is ${typeof ordinalDirection}`
520-
).toBe(expectedType);
520+
).toBeTypeOf(expectedType);
521521
expect(ordinalDirectionLength).lessThanOrEqual(2);
522522
});
523523
});
@@ -531,9 +531,9 @@ describe('address', () => {
531531
'The cardinal direction when useAbbr is true should';
532532

533533
expect(
534-
typeof cardinalDirection,
534+
cardinalDirection,
535535
`${prefixErrorMessage} be of type ${expectedType}. Current is ${typeof cardinalDirection}`
536-
).toBe(expectedType);
536+
).toBeTypeOf(expectedType);
537537
expect(cardinalDirectionLength).lessThanOrEqual(2);
538538
});
539539
});
@@ -578,8 +578,8 @@ describe('address', () => {
578578
);
579579

580580
expect(coordinate.length).toBe(2);
581-
expect(typeof coordinate[0]).toBe('string');
582-
expect(typeof coordinate[1]).toBe('string');
581+
expect(coordinate[0]).toBeTypeOf('string');
582+
expect(coordinate[1]).toBeTypeOf('string');
583583

584584
const latFloat2 = parseFloat(coordinate[0]);
585585
expect(latFloat2).greaterThanOrEqual(-90.0);
@@ -616,8 +616,8 @@ describe('address', () => {
616616
);
617617

618618
expect(coordinate.length).toBe(2);
619-
expect(typeof coordinate[0]).toBe('string');
620-
expect(typeof coordinate[1]).toBe('string');
619+
expect(coordinate[0]).toBeTypeOf('string');
620+
expect(coordinate[1]).toBeTypeOf('string');
621621

622622
const distanceToTarget =
623623
Math.pow(coordinate[0] - latitude, 2) +
@@ -640,8 +640,8 @@ describe('address', () => {
640640
);
641641

642642
expect(coordinate.length).toBe(2);
643-
expect(typeof coordinate[0]).toBe('string');
644-
expect(typeof coordinate[1]).toBe('string');
643+
expect(coordinate[0]).toBeTypeOf('string');
644+
expect(coordinate[1]).toBeTypeOf('string');
645645

646646
// const distanceToTarget =
647647
// Math.pow(coordinate[0] - latitude, 2) +

test/all_functional.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('functional tests', () => {
6767
it(meth + '()', () => {
6868
const result = faker[module][meth]();
6969
if (meth === 'boolean') {
70-
expect(typeof result).toBe('boolean');
70+
expect(result).toBeTypeOf('boolean');
7171
} else {
7272
expect(result).toBeTruthy();
7373
}
@@ -98,7 +98,7 @@ describe('faker.fake functional tests', () => {
9898
// an undefined result usually means an error
9999
expect(result).toBeDefined();
100100
// if (meth === 'boolean') {
101-
// expect(typeof result).toBe('boolean');
101+
// expect(result).toBeTypeOf('boolean');
102102
// } else {
103103
// expect(result).toBeTruthy();
104104
// }

test/company.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,30 @@ describe('company', () => {
105105
const actual = faker.company.companyName();
106106

107107
expect(actual).toBeTruthy();
108-
expect(typeof actual).toBe('string');
108+
expect(actual).toBeTypeOf('string');
109109
});
110110

111111
it('should return a random company name with format 0', () => {
112112
const actual = faker.company.companyName(0);
113113

114114
expect(actual).toBeTruthy();
115-
expect(typeof actual).toBe('string');
115+
expect(actual).toBeTypeOf('string');
116116
expect(actual).includes(' ');
117117
});
118118

119119
it('should return a random company name with format 1', () => {
120120
const actual = faker.company.companyName(1);
121121

122122
expect(actual).toBeTruthy();
123-
expect(typeof actual).toBe('string');
123+
expect(actual).toBeTypeOf('string');
124124
expect(actual).includes(' - ');
125125
});
126126

127127
it('should return a random company name with format 2', () => {
128128
const actual = faker.company.companyName(2);
129129

130130
expect(actual).toBeTruthy();
131-
expect(typeof actual).toBe('string');
131+
expect(actual).toBeTypeOf('string');
132132
expect(actual).includes(', ');
133133
expect(actual).includes(' and ');
134134
});
@@ -139,7 +139,7 @@ describe('company', () => {
139139
const actual = faker.company.companySuffix();
140140

141141
expect(actual).toBeTruthy();
142-
expect(typeof actual).toBe('string');
142+
expect(actual).toBeTypeOf('string');
143143
expect(faker.definitions.company.suffix).toContain(actual);
144144
});
145145
});
@@ -149,7 +149,7 @@ describe('company', () => {
149149
const actual = faker.company.catchPhrase();
150150

151151
expect(actual).toBeTruthy();
152-
expect(typeof actual).toBe('string');
152+
expect(actual).toBeTypeOf('string');
153153

154154
const parts = actual.split(' ');
155155

@@ -162,7 +162,7 @@ describe('company', () => {
162162
const actual = faker.company.bs();
163163

164164
expect(actual).toBeTruthy();
165-
expect(typeof actual).toBe('string');
165+
expect(actual).toBeTypeOf('string');
166166

167167
const parts = actual.split(' ');
168168

@@ -175,7 +175,7 @@ describe('company', () => {
175175
const actual = faker.company.catchPhraseAdjective();
176176

177177
expect(actual).toBeTruthy();
178-
expect(typeof actual).toBe('string');
178+
expect(actual).toBeTypeOf('string');
179179
expect(faker.definitions.company.adjective).toContain(actual);
180180
});
181181
});
@@ -185,7 +185,7 @@ describe('company', () => {
185185
const actual = faker.company.catchPhraseDescriptor();
186186

187187
expect(actual).toBeTruthy();
188-
expect(typeof actual).toBe('string');
188+
expect(actual).toBeTypeOf('string');
189189
expect(faker.definitions.company.descriptor).toContain(actual);
190190
});
191191
});
@@ -195,7 +195,7 @@ describe('company', () => {
195195
const actual = faker.company.catchPhraseNoun();
196196

197197
expect(actual).toBeTruthy();
198-
expect(typeof actual).toBe('string');
198+
expect(actual).toBeTypeOf('string');
199199
expect(faker.definitions.company.noun).toContain(actual);
200200
});
201201
});
@@ -205,7 +205,7 @@ describe('company', () => {
205205
const actual = faker.company.bsAdjective();
206206

207207
expect(actual).toBeTruthy();
208-
expect(typeof actual).toBe('string');
208+
expect(actual).toBeTypeOf('string');
209209
expect(faker.definitions.company.bs_adjective).toContain(actual);
210210
});
211211
});
@@ -215,7 +215,7 @@ describe('company', () => {
215215
const actual = faker.company.bsBuzz();
216216

217217
expect(actual).toBeTruthy();
218-
expect(typeof actual).toBe('string');
218+
expect(actual).toBeTypeOf('string');
219219
expect(faker.definitions.company.bs_verb).toContain(actual);
220220
});
221221
});
@@ -225,7 +225,7 @@ describe('company', () => {
225225
const actual = faker.company.bsNoun();
226226

227227
expect(actual).toBeTruthy();
228-
expect(typeof actual).toBe('string');
228+
expect(actual).toBeTypeOf('string');
229229
expect(faker.definitions.company.bs_noun).toContain(actual);
230230
});
231231
});

test/database.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('database', () => {
6262
it('should return a column name from array', () => {
6363
const column = faker.database.column();
6464
expect(column).toBeTruthy();
65-
expect(typeof column).toBe('string');
65+
expect(column).toBeTypeOf('string');
6666
expect(faker.definitions.database.column).toContain(column);
6767
});
6868
});
@@ -71,7 +71,7 @@ describe('database', () => {
7171
it('should return a collation from array', () => {
7272
const collation = faker.database.collation();
7373
expect(collation).toBeTruthy();
74-
expect(typeof collation).toBe('string');
74+
expect(collation).toBeTypeOf('string');
7575
expect(faker.definitions.database.collation).toContain(collation);
7676
});
7777
});
@@ -80,7 +80,7 @@ describe('database', () => {
8080
it('should return an engine from array', () => {
8181
const engine = faker.database.engine();
8282
expect(engine).toBeTruthy();
83-
expect(typeof engine).toBe('string');
83+
expect(engine).toBeTypeOf('string');
8484
expect(faker.definitions.database.engine).toContain(engine);
8585
});
8686
});
@@ -89,7 +89,7 @@ describe('database', () => {
8989
it('should return a column type from array', () => {
9090
const type = faker.database.type();
9191
expect(type).toBeTruthy();
92-
expect(typeof type).toBe('string');
92+
expect(type).toBeTypeOf('string');
9393
expect(faker.definitions.database.type).toContain(type);
9494
});
9595
});

test/datatype.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ describe('datatype', () => {
236236
faker.seed(seed);
237237

238238
const actual = faker.datatype.datetime();
239-
expect(typeof actual).toBe('object');
239+
expect(actual).toBeTypeOf('object');
240240
});
241241
continue;
242242
}
@@ -533,7 +533,7 @@ describe('datatype', () => {
533533
describe('datetime', () => {
534534
it('check validity of date and if returned value is created by Date()', () => {
535535
const date = faker.datatype.datetime();
536-
expect(typeof date).toBe('object');
536+
expect(date).toBeTypeOf('object');
537537
expect(date.getTime()).not.toBeNaN();
538538
expect(Object.prototype.toString.call(date)).toBe('[object Date]');
539539
});
@@ -542,7 +542,7 @@ describe('datatype', () => {
542542
describe('string', () => {
543543
it('should generate a string value', () => {
544544
const generatedString = faker.datatype.string();
545-
expect(typeof generatedString).toBe('string');
545+
expect(generatedString).toBeTypeOf('string');
546546
expect(generatedString).toHaveLength(10);
547547
});
548548

@@ -563,7 +563,7 @@ describe('datatype', () => {
563563
describe('boolean', () => {
564564
it('generates a boolean value', () => {
565565
const bool = faker.datatype.boolean();
566-
expect(typeof bool).toBe('boolean');
566+
expect(bool).toBeTypeOf('boolean');
567567
});
568568
});
569569

@@ -593,7 +593,7 @@ describe('datatype', () => {
593593
describe('json', () => {
594594
it('generates a valid json object', () => {
595595
const jsonObject = faker.datatype.json();
596-
expect(typeof jsonObject).toBe('string');
596+
expect(jsonObject).toBeTypeOf('string');
597597
expect(JSON.parse(jsonObject)).toBeTruthy();
598598
});
599599
});
@@ -614,7 +614,7 @@ describe('datatype', () => {
614614
describe('bigInt', () => {
615615
it('should generate a bigInt value', () => {
616616
const generateBigInt = faker.datatype.bigInt();
617-
expect(typeof generateBigInt).toBe('bigint');
617+
expect(generateBigInt).toBeTypeOf('bigint');
618618
});
619619
});
620620
}

0 commit comments

Comments
 (0)