From 188309a59cfe6fbd33e120dedf3bdfef3276d641 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Thu, 14 Nov 2024 22:50:04 +0100 Subject: infra(unicorn): consistent-function-scoping (#3255) --- test/modules/date.spec.ts | 26 +++++++++++++------------- test/modules/git.spec.ts | 23 ++++++++++++----------- test/modules/number.spec.ts | 16 ++++++++-------- 3 files changed, 33 insertions(+), 32 deletions(-) (limited to 'test/modules') 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(/^(.*) { 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(/^(.*) 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(); -- cgit v1.2.3