diff options
| author | ST-DDT <[email protected]> | 2024-06-21 11:44:57 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-21 09:44:57 +0000 |
| commit | d6924f7fbb9403d106022f58a1bda3b159e88ae6 (patch) | |
| tree | 36ed943a8ea837a4538073c7e51b6ed831cb190d /test | |
| parent | 5801cc5cad8324a114d08733fafa31f7632d1118 (diff) | |
| download | faker-d6924f7fbb9403d106022f58a1bda3b159e88ae6.tar.xz faker-d6924f7fbb9403d106022f58a1bda3b159e88ae6.zip | |
feat(date)!: separate timeZone method (#2947)
Diffstat (limited to 'test')
| -rw-r--r-- | test/modules/__snapshots__/date.spec.ts.snap | 6 | ||||
| -rw-r--r-- | test/modules/__snapshots__/location.spec.ts.snap | 4 | ||||
| -rw-r--r-- | test/modules/date.spec.ts | 26 | ||||
| -rw-r--r-- | test/modules/location.spec.ts | 39 |
4 files changed, 71 insertions, 4 deletions
diff --git a/test/modules/__snapshots__/date.spec.ts.snap b/test/modules/__snapshots__/date.spec.ts.snap index 236c367b..ee5faa6d 100644 --- a/test/modules/__snapshots__/date.spec.ts.snap +++ b/test/modules/__snapshots__/date.spec.ts.snap @@ -115,6 +115,8 @@ exports[`date > 42 > soon > with only string refDate 1`] = `2021-02-22T02:08:36. exports[`date > 42 > soon > with value 1`] = `2021-02-25T11:02:38.999Z`; +exports[`date > 42 > timeZone 1`] = `"America/North_Dakota/Center"`; + exports[`date > 42 > weekday > noArgs 1`] = `"Saturday"`; exports[`date > 42 > weekday > with abbreviated = true 1`] = `"Sat"`; @@ -239,6 +241,8 @@ exports[`date > 1211 > soon > with only string refDate 1`] = `2021-02-22T15:26:1 exports[`date > 1211 > soon > with value 1`] = `2021-03-02T23:59:57.196Z`; +exports[`date > 1211 > timeZone 1`] = `"Pacific/Fiji"`; + exports[`date > 1211 > weekday > noArgs 1`] = `"Wednesday"`; exports[`date > 1211 > weekday > with abbreviated = true 1`] = `"Wed"`; @@ -361,6 +365,8 @@ exports[`date > 1337 > soon > with only string refDate 1`] = `2021-02-21T23:26:3 exports[`date > 1337 > soon > with value 1`] = `2021-02-24T08:02:25.768Z`; +exports[`date > 1337 > timeZone 1`] = `"America/Guadeloupe"`; + exports[`date > 1337 > weekday > noArgs 1`] = `"Monday"`; exports[`date > 1337 > weekday > with abbreviated = true 1`] = `"Mon"`; diff --git a/test/modules/__snapshots__/location.spec.ts.snap b/test/modules/__snapshots__/location.spec.ts.snap index 5d4b1d31..b53acbda 100644 --- a/test/modules/__snapshots__/location.spec.ts.snap +++ b/test/modules/__snapshots__/location.spec.ts.snap @@ -128,7 +128,7 @@ exports[`location > 42 > streetAddress > with boolean 1`] = `"9751 Anderson Thro exports[`location > 42 > streetAddress > with useFullAddress options 1`] = `"9751 Anderson Throughway Suite 709"`; -exports[`location > 42 > timeZone 1`] = `"America/North_Dakota/New_Salem"`; +exports[`location > 42 > timeZone 1`] = `"America/North_Dakota/Center"`; exports[`location > 42 > zipCode > noArgs 1`] = `"97511"`; @@ -400,7 +400,7 @@ exports[`location > 1337 > streetAddress > with boolean 1`] = `"22435 Westley Ri exports[`location > 1337 > streetAddress > with useFullAddress options 1`] = `"22435 Westley Ridges Apt. 461"`; -exports[`location > 1337 > timeZone 1`] = `"America/Guatemala"`; +exports[`location > 1337 > timeZone 1`] = `"America/Guadeloupe"`; exports[`location > 1337 > zipCode > noArgs 1`] = `"12435"`; diff --git a/test/modules/date.spec.ts b/test/modules/date.spec.ts index 811bd81b..e30da8d9 100644 --- a/test/modules/date.spec.ts +++ b/test/modules/date.spec.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; -import { FakerError, faker, fakerAZ } from '../../src'; +import { FakerError, allLocales, faker, fakerAZ } from '../../src'; import { seededTests } from '../support/seeded-runs'; import { times } from './../support/times'; @@ -59,6 +59,8 @@ describe('date', () => { }); }); + t.it('timeZone'); + t.describe('between', (t) => { t.it('with string dates', { from: '2021-02-21T17:09:15.711Z', @@ -653,9 +655,31 @@ describe('date', () => { ); }); }); + + describe('timeZone', () => { + it('should return a random timezone', () => { + const actual = faker.date.timeZone(); + expect(faker.definitions.date.time_zone).toContain(actual); + }); + }); } ); + describe('definitions', () => { + describe('timeZone', () => { + it('should have timezones in the base locale', () => { + expect(allLocales.base.date?.time_zone).toSatisfy(Array.isArray); + expect(allLocales.base.date?.time_zone?.length).toBeGreaterThan(0); + }); + + it.each( + Object.entries(allLocales).filter(([locale]) => locale !== 'base') + )('should not have any timezones in %s', (_, data) => { + expect(data.date?.time_zone).toBeUndefined(); + }); + }); + }); + describe('refDateSource', () => { afterEach(() => { faker.setDefaultRefDate(); diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts index dc82757d..1291efd3 100644 --- a/test/modules/location.spec.ts +++ b/test/modules/location.spec.ts @@ -1,5 +1,11 @@ import { describe, expect, it } from 'vitest'; -import { FakerError, faker, fakerEN_CA, fakerEN_US } from '../../src'; +import { + FakerError, + allLocales, + faker, + fakerEN_CA, + fakerEN_US, +} from '../../src'; import { seededTests } from '../support/seeded-runs'; import { times } from './../support/times'; @@ -390,6 +396,37 @@ describe('location', () => { } ); }); + + describe('timeZone', () => { + it('should return a random timezone', () => { + const actual = faker.location.timeZone(); + expect(faker.definitions.location.time_zone).toContain(actual); + }); + }); } ); }); + +describe('definitions', () => { + describe('timeZone', () => { + it.each(Object.entries(allLocales))( + 'locale data for %s should be a subset of the base locale', + (locale, data) => { + if (locale === 'base') { + expect(data.location?.time_zone).toSatisfy(Array.isArray); + expect(data.location?.time_zone?.length).toBeGreaterThan(0); + expect(data.location?.time_zone).toEqual( + allLocales.base.date?.time_zone + ); + } else if (data.location?.time_zone != null) { + expect(data.location.time_zone).toSatisfy(Array.isArray); + expect(data.location.time_zone.length).toBeGreaterThan(0); + // expected and actual are flipped here + expect(allLocales.base.date?.time_zone).toEqual( + expect.arrayContaining(data.location.time_zone) + ); + } + } + ); + }); +}); |
