Skip to content

Commit

Permalink
test: use toBeTypeOf (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Feb 20, 2022
1 parent 2448aab commit bfa7946
Show file tree
Hide file tree
Showing 19 changed files with 172 additions and 172 deletions.
36 changes: 18 additions & 18 deletions test/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('address', () => {
for (let i = 0; i < 100; i++) {
const latitude = faker.address.latitude();

expect(typeof latitude).toBe('string');
expect(latitude).toBeTypeOf('string');

const latitude_float = parseFloat(latitude);

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

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

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

expect(typeof longitude).toBe('string');
expect(longitude).toBeTypeOf('string');

const longitude_float = parseFloat(longitude);

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

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

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

expect(
typeof direction,
direction,
`${prefixErrorMessage} be of type string. Current is ${typeof direction}`
).toBe('string');
).toBeTypeOf('string');
expect(lengthDirection).lessThanOrEqual(2);
});
});
Expand All @@ -515,9 +515,9 @@ describe('address', () => {
'The ordinal direction when useAbbr is true should';

expect(
typeof ordinalDirection,
ordinalDirection,
`${prefixErrorMessage} be equal ${expectedType}. Current is ${typeof ordinalDirection}`
).toBe(expectedType);
).toBeTypeOf(expectedType);
expect(ordinalDirectionLength).lessThanOrEqual(2);
});
});
Expand All @@ -531,9 +531,9 @@ describe('address', () => {
'The cardinal direction when useAbbr is true should';

expect(
typeof cardinalDirection,
cardinalDirection,
`${prefixErrorMessage} be of type ${expectedType}. Current is ${typeof cardinalDirection}`
).toBe(expectedType);
).toBeTypeOf(expectedType);
expect(cardinalDirectionLength).lessThanOrEqual(2);
});
});
Expand Down Expand Up @@ -578,8 +578,8 @@ describe('address', () => {
);

expect(coordinate.length).toBe(2);
expect(typeof coordinate[0]).toBe('string');
expect(typeof coordinate[1]).toBe('string');
expect(coordinate[0]).toBeTypeOf('string');
expect(coordinate[1]).toBeTypeOf('string');

const latFloat2 = parseFloat(coordinate[0]);
expect(latFloat2).greaterThanOrEqual(-90.0);
Expand Down Expand Up @@ -616,8 +616,8 @@ describe('address', () => {
);

expect(coordinate.length).toBe(2);
expect(typeof coordinate[0]).toBe('string');
expect(typeof coordinate[1]).toBe('string');
expect(coordinate[0]).toBeTypeOf('string');
expect(coordinate[1]).toBeTypeOf('string');

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

expect(coordinate.length).toBe(2);
expect(typeof coordinate[0]).toBe('string');
expect(typeof coordinate[1]).toBe('string');
expect(coordinate[0]).toBeTypeOf('string');
expect(coordinate[1]).toBeTypeOf('string');

// const distanceToTarget =
// Math.pow(coordinate[0] - latitude, 2) +
Expand Down
4 changes: 2 additions & 2 deletions test/all_functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('functional tests', () => {
it(meth + '()', () => {
const result = faker[module][meth]();
if (meth === 'boolean') {
expect(typeof result).toBe('boolean');
expect(result).toBeTypeOf('boolean');
} else {
expect(result).toBeTruthy();
}
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('faker.fake functional tests', () => {
// an undefined result usually means an error
expect(result).toBeDefined();
// if (meth === 'boolean') {
// expect(typeof result).toBe('boolean');
// expect(result).toBeTypeOf('boolean');
// } else {
// expect(result).toBeTruthy();
// }
Expand Down
26 changes: 13 additions & 13 deletions test/company.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,30 @@ describe('company', () => {
const actual = faker.company.companyName();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
});

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

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(actual).includes(' ');
});

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

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(actual).includes(' - ');
});

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

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(actual).includes(', ');
expect(actual).includes(' and ');
});
Expand All @@ -139,7 +139,7 @@ describe('company', () => {
const actual = faker.company.companySuffix();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.suffix).toContain(actual);
});
});
Expand All @@ -149,7 +149,7 @@ describe('company', () => {
const actual = faker.company.catchPhrase();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');

const parts = actual.split(' ');

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

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');

const parts = actual.split(' ');

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

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.adjective).toContain(actual);
});
});
Expand All @@ -185,7 +185,7 @@ describe('company', () => {
const actual = faker.company.catchPhraseDescriptor();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.descriptor).toContain(actual);
});
});
Expand All @@ -195,7 +195,7 @@ describe('company', () => {
const actual = faker.company.catchPhraseNoun();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.noun).toContain(actual);
});
});
Expand All @@ -205,7 +205,7 @@ describe('company', () => {
const actual = faker.company.bsAdjective();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.bs_adjective).toContain(actual);
});
});
Expand All @@ -215,7 +215,7 @@ describe('company', () => {
const actual = faker.company.bsBuzz();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.bs_verb).toContain(actual);
});
});
Expand All @@ -225,7 +225,7 @@ describe('company', () => {
const actual = faker.company.bsNoun();

expect(actual).toBeTruthy();
expect(typeof actual).toBe('string');
expect(actual).toBeTypeOf('string');
expect(faker.definitions.company.bs_noun).toContain(actual);
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('database', () => {
it('should return a column name from array', () => {
const column = faker.database.column();
expect(column).toBeTruthy();
expect(typeof column).toBe('string');
expect(column).toBeTypeOf('string');
expect(faker.definitions.database.column).toContain(column);
});
});
Expand All @@ -71,7 +71,7 @@ describe('database', () => {
it('should return a collation from array', () => {
const collation = faker.database.collation();
expect(collation).toBeTruthy();
expect(typeof collation).toBe('string');
expect(collation).toBeTypeOf('string');
expect(faker.definitions.database.collation).toContain(collation);
});
});
Expand All @@ -80,7 +80,7 @@ describe('database', () => {
it('should return an engine from array', () => {
const engine = faker.database.engine();
expect(engine).toBeTruthy();
expect(typeof engine).toBe('string');
expect(engine).toBeTypeOf('string');
expect(faker.definitions.database.engine).toContain(engine);
});
});
Expand All @@ -89,7 +89,7 @@ describe('database', () => {
it('should return a column type from array', () => {
const type = faker.database.type();
expect(type).toBeTruthy();
expect(typeof type).toBe('string');
expect(type).toBeTypeOf('string');
expect(faker.definitions.database.type).toContain(type);
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('datatype', () => {
faker.seed(seed);

const actual = faker.datatype.datetime();
expect(typeof actual).toBe('object');
expect(actual).toBeTypeOf('object');
});
continue;
}
Expand Down Expand Up @@ -533,7 +533,7 @@ describe('datatype', () => {
describe('datetime', () => {
it('check validity of date and if returned value is created by Date()', () => {
const date = faker.datatype.datetime();
expect(typeof date).toBe('object');
expect(date).toBeTypeOf('object');
expect(date.getTime()).not.toBeNaN();
expect(Object.prototype.toString.call(date)).toBe('[object Date]');
});
Expand All @@ -542,7 +542,7 @@ describe('datatype', () => {
describe('string', () => {
it('should generate a string value', () => {
const generatedString = faker.datatype.string();
expect(typeof generatedString).toBe('string');
expect(generatedString).toBeTypeOf('string');
expect(generatedString).toHaveLength(10);
});

Expand All @@ -563,7 +563,7 @@ describe('datatype', () => {
describe('boolean', () => {
it('generates a boolean value', () => {
const bool = faker.datatype.boolean();
expect(typeof bool).toBe('boolean');
expect(bool).toBeTypeOf('boolean');
});
});

Expand Down Expand Up @@ -593,7 +593,7 @@ describe('datatype', () => {
describe('json', () => {
it('generates a valid json object', () => {
const jsonObject = faker.datatype.json();
expect(typeof jsonObject).toBe('string');
expect(jsonObject).toBeTypeOf('string');
expect(JSON.parse(jsonObject)).toBeTruthy();
});
});
Expand All @@ -614,7 +614,7 @@ describe('datatype', () => {
describe('bigInt', () => {
it('should generate a bigInt value', () => {
const generateBigInt = faker.datatype.bigInt();
expect(typeof generateBigInt).toBe('bigint');
expect(generateBigInt).toBeTypeOf('bigint');
});
});
}
Expand Down
Loading

0 comments on commit bfa7946

Please sign in to comment.