diff options
| author | ST-DDT <[email protected]> | 2024-11-14 22:50:04 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-11-14 21:50:04 +0000 |
| commit | 188309a59cfe6fbd33e120dedf3bdfef3276d641 (patch) | |
| tree | 079d062e07065b11ae0bcf8c8cb964174a842080 /test/modules | |
| parent | a54c1edb87e88b198966d248d5273c9898c32798 (diff) | |
| download | faker-188309a59cfe6fbd33e120dedf3bdfef3276d641.tar.xz faker-188309a59cfe6fbd33e120dedf3bdfef3276d641.zip | |
infra(unicorn): consistent-function-scoping (#3255)
Diffstat (limited to 'test/modules')
| -rw-r--r-- | test/modules/date.spec.ts | 26 | ||||
| -rw-r--r-- | test/modules/git.spec.ts | 23 | ||||
| -rw-r--r-- | test/modules/number.spec.ts | 16 |
3 files changed, 33 insertions, 32 deletions
diff --git a/test/modules/date.spec.ts b/test/modules/date.spec.ts index e30da8d9..19a2d0a7 100644 --- a/test/modules/date.spec.ts +++ b/test/modules/date.spec.ts @@ -12,6 +12,19 @@ const converterMap = [ const NON_SEEDED_BASED_RUN = 5; const refDate = '2021-02-21T17:09:15.711Z'; +function calculateAge(birthdate: Date, refDate: Date): number { + let age = refDate.getFullYear() - birthdate.getFullYear(); + if ( + refDate.getMonth() < birthdate.getMonth() || + (refDate.getMonth() === birthdate.getMonth() && + refDate.getDate() < birthdate.getDate()) + ) { + age--; + } + + return age; +} + describe('date', () => { seededTests(faker, 'date', (t) => { t.describe('anytime', (t) => { @@ -530,19 +543,6 @@ describe('date', () => { }); describe('birthdate', () => { - function calculateAge(birthdate: Date, refDate: Date): number { - let age = refDate.getFullYear() - birthdate.getFullYear(); - if ( - refDate.getMonth() < birthdate.getMonth() || - (refDate.getMonth() === birthdate.getMonth() && - refDate.getDate() < birthdate.getDate()) - ) { - age--; - } - - return age; - } - it('returns a random birthdate', () => { const birthdate = faker.date.birthdate(); expect(birthdate).toBeInstanceOf(Date); diff --git a/test/modules/git.spec.ts b/test/modules/git.spec.ts index e4692b20..164b19c6 100644 --- a/test/modules/git.spec.ts +++ b/test/modules/git.spec.ts @@ -8,6 +8,16 @@ const NON_SEEDED_BASED_RUN = 5; const refDate = '2020-01-01T00:00:00.000Z'; +function isValidCommitAuthor(email: string): boolean { + // `validator.isEmail()` does not support display names + // that contain unquoted characters like . output by Git so we need + // to quote the display name + const quotedEmail = email.replace(/^(.*) </, '"$1" <'); + return validator.isEmail(quotedEmail, { + require_display_name: true, + }); +} + describe('git', () => { seededTests(faker, 'git', (t) => { t.itEach('branch', 'commitMessage'); @@ -56,27 +66,18 @@ describe('git', () => { expect(parts.length).toBeLessThanOrEqual(7); expect(parts[0]).toMatch(/^commit [a-f0-9]+$/); - const isValidAuthor = (email: string) => { - // `validator.isEmail()` does not support display names - // that contain unquoted characters like . output by Git so we need - // to quote the display name - const quotedEmail = email.replace(/^(.*) </, '"$1" <'); - return validator.isEmail(quotedEmail, { - require_display_name: true, - }); - }; const authorRegex = /^Author: .*$/; if (parts.length === 7) { expect(parts[1]).toMatch(/^Merge: [a-f0-9]+ [a-f0-9]+$/); expect(parts[2]).toMatch(authorRegex); - expect(parts[2].substring(8)).toSatisfy(isValidAuthor); + expect(parts[2].substring(8)).toSatisfy(isValidCommitAuthor); expect(parts[3]).toMatch(/^Date: .+$/); expect(parts[4]).toBe(''); expect(parts[5]).toMatch(/^\s{4}.+$/); } else { expect(parts[1]).toMatch(authorRegex); - expect(parts[1].substring(8)).toSatisfy(isValidAuthor); + expect(parts[1].substring(8)).toSatisfy(isValidCommitAuthor); expect(parts[2]).toMatch(/^Date: .+$/); expect(parts[3]).toBe(''); expect(parts[4]).toMatch(/^\s{4}.+$/); diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts index cfd50b20..3b21f64c 100644 --- a/test/modules/number.spec.ts +++ b/test/modules/number.spec.ts @@ -5,6 +5,14 @@ import { seededTests } from '../support/seeded-runs'; import { MERSENNE_MAX_VALUE } from '../utils/mersenne-test-utils'; import { times } from './../support/times'; +function isFloat(value: number): boolean { + return value % 1 !== 0; +} + +function isBinary(str: string): boolean { + return [...str].every((char) => char === '0' || char === '1'); +} + describe('number', () => { seededTests(faker, 'number', (t) => { t.describeEach( @@ -259,10 +267,6 @@ describe('number', () => { }); describe('float', () => { - function isFloat(value: number) { - return value % 1 !== 0; - } - it('should return a float between 0 and 1 (inclusive) by default', () => { const actual = faker.number.float(); @@ -405,10 +409,6 @@ describe('number', () => { }); describe('binary', () => { - function isBinary(str: string) { - return [...str].every((char) => char === '0' || char === '1'); - } - it('generates single binary character when no additional argument was provided', () => { const binary = faker.number.binary(); |
