diff options
| author | ST-DDT <[email protected]> | 2023-04-26 06:16:51 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-26 06:16:51 +0200 |
| commit | 3fc7bf1b24ed67696b4824abcd9fa14af43cb66d (patch) | |
| tree | aeead10dc7e2ab4a31efd90fc4a5e342b8543f27 /test | |
| parent | 4d0458c96071917c8c3bb85fa61544caf8ff1763 (diff) | |
| download | faker-3fc7bf1b24ed67696b4824abcd9fa14af43cb66d.tar.xz faker-3fc7bf1b24ed67696b4824abcd9fa14af43cb66d.zip | |
feat(date): introduce anytime (#2096)
Diffstat (limited to 'test')
| -rw-r--r-- | test/__snapshots__/date.spec.ts.snap | 18 | ||||
| -rw-r--r-- | test/date.spec.ts | 19 |
2 files changed, 36 insertions, 1 deletions
diff --git a/test/__snapshots__/date.spec.ts.snap b/test/__snapshots__/date.spec.ts.snap index a42c8786..701c8cc7 100644 --- a/test/__snapshots__/date.spec.ts.snap +++ b/test/__snapshots__/date.spec.ts.snap @@ -1,5 +1,11 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`date > 42 > anytime > with only Date refDate 1`] = `2020-11-22T03:05:49.801Z`; + +exports[`date > 42 > anytime > with only number refDate 1`] = `2020-11-22T03:05:49.801Z`; + +exports[`date > 42 > anytime > with only string refDate 1`] = `2020-11-22T03:05:49.801Z`; + exports[`date > 42 > between > with Date dates 1`] = `2021-03-15T19:30:57.091Z`; exports[`date > 42 > between > with mixed dates 1`] = `2021-03-15T19:30:57.091Z`; @@ -121,6 +127,12 @@ exports[`date > 42 > weekday > with abbreviated = true and context = true 1`] = exports[`date > 42 > weekday > with context = true 1`] = `"Tuesday"`; +exports[`date > 1211 > anytime > with only Date refDate 1`] = `2021-12-31T12:49:38.848Z`; + +exports[`date > 1211 > anytime > with only number refDate 1`] = `2021-12-31T12:49:38.848Z`; + +exports[`date > 1211 > anytime > with only string refDate 1`] = `2021-12-31T12:49:38.848Z`; + exports[`date > 1211 > between > with Date dates 1`] = `2021-04-17T11:58:13.327Z`; exports[`date > 1211 > between > with mixed dates 1`] = `2021-04-17T11:58:13.327Z`; @@ -243,6 +255,12 @@ exports[`date > 1211 > weekday > with abbreviated = true and context = true 1`] exports[`date > 1211 > weekday > with context = true 1`] = `"Saturday"`; +exports[`date > 1337 > anytime > with only Date refDate 1`] = `2020-08-31T23:49:36.088Z`; + +exports[`date > 1337 > anytime > with only number refDate 1`] = `2020-08-31T23:49:36.088Z`; + +exports[`date > 1337 > anytime > with only string refDate 1`] = `2020-08-31T23:49:36.088Z`; + exports[`date > 1337 > between > with Date dates 1`] = `2021-03-09T04:11:24.667Z`; exports[`date > 1337 > between > with mixed dates 1`] = `2021-03-09T04:11:24.667Z`; diff --git a/test/date.spec.ts b/test/date.spec.ts index bfa01e7d..d456b53c 100644 --- a/test/date.spec.ts +++ b/test/date.spec.ts @@ -13,6 +13,14 @@ const refDate = '2021-02-21T17:09:15.711Z'; describe('date', () => { seededTests(faker, 'date', (t) => { + t.describe('anytime', (t) => { + t.it('with only string refDate', { refDate }) + .it('with only Date refDate', { refDate: new Date(refDate) }) + .it('with only number refDate', { + refDate: new Date(refDate).getTime(), + }); + }); + t.describeEach( 'past', 'future' @@ -188,12 +196,21 @@ describe('date', () => { }); // No changes to these methods - t.skip('birthdate').skip('month').skip('weekday'); + t.skip('anytime').skip('birthdate').skip('month').skip('weekday'); }); }); describe(`random seeded tests for seed ${faker.seed()}`, () => { for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { + describe('anytime()', () => { + it('should return a date', () => { + const actual = faker.date.anytime(); + + expect(actual).toBeDefined(); + expect(actual).toBeInstanceOf(Date); + }); + }); + describe('past()', () => { it('should return a date 5 years in the past', () => { const today = new Date(); |
