diff options
| author | Shinigami <[email protected]> | 2024-03-05 10:56:25 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-05 09:56:25 +0000 |
| commit | e868060c87cbca3c1bf90465d61fc39a4eea1f9c (patch) | |
| tree | 5ca57dc9eae4683ff82f951478e6a810c3f71a96 /test/modules | |
| parent | 2bf897464cdda53886380590d64236658102cdda (diff) | |
| download | faker-e868060c87cbca3c1bf90465d61fc39a4eea1f9c.tar.xz faker-e868060c87cbca3c1bf90465d61fc39a4eea1f9c.zip | |
refactor(date)!: remove v8 deprecated date methods (#2704)
Diffstat (limited to 'test/modules')
| -rw-r--r-- | test/modules/__snapshots__/date.spec.ts.snap | 216 | ||||
| -rw-r--r-- | test/modules/date.spec.ts | 277 |
2 files changed, 5 insertions, 488 deletions
diff --git a/test/modules/__snapshots__/date.spec.ts.snap b/test/modules/__snapshots__/date.spec.ts.snap index 1b28f47b..9b3c3d76 100644 --- a/test/modules/__snapshots__/date.spec.ts.snap +++ b/test/modules/__snapshots__/date.spec.ts.snap @@ -380,219 +380,3 @@ exports[`date > 1337 > weekday > with abbreviated = true 1`] = `"Mon"`; exports[`date > 1337 > weekday > with abbreviated = true and context = true 1`] = `"Mon"`; exports[`date > 1337 > weekday > with context = true 1`] = `"Monday"`; - -exports[`date > deprecated > 42 > between > with Date dates 1`] = `2021-03-15T19:30:57.115Z`; - -exports[`date > deprecated > 42 > between > with string dates 1`] = `2021-03-15T19:30:57.115Z`; - -exports[`date > deprecated > 42 > betweens > with Date dates 1`] = ` -[ - 2021-03-15T19:30:57.115Z, - 2021-04-05T21:40:57.332Z, - 2021-04-18T19:23:52.947Z, -] -`; - -exports[`date > deprecated > 42 > betweens > with Date dates and count 1`] = ` -[ - 2021-03-02T22:04:55.366Z, - 2021-03-15T19:30:57.115Z, - 2021-03-29T00:52:30.236Z, - 2021-04-05T21:40:57.332Z, - 2021-04-18T19:23:52.947Z, -] -`; - -exports[`date > deprecated > 42 > betweens > with string dates 1`] = ` -[ - 2021-03-15T19:30:57.115Z, - 2021-04-05T21:40:57.332Z, - 2021-04-18T19:23:52.947Z, -] -`; - -exports[`date > deprecated > 42 > betweens > with string dates and count 1`] = ` -[ - 2021-03-02T22:04:55.366Z, - 2021-03-15T19:30:57.115Z, - 2021-03-29T00:52:30.236Z, - 2021-04-05T21:40:57.332Z, - 2021-04-18T19:23:52.947Z, -] -`; - -exports[`date > deprecated > 42 > future > with only Date refDate 1`] = `2021-07-08T10:07:33.524Z`; - -exports[`date > deprecated > 42 > future > with only number refDate 1`] = `2021-07-08T10:07:33.524Z`; - -exports[`date > deprecated > 42 > future > with only string refDate 1`] = `2021-07-08T10:07:33.524Z`; - -exports[`date > deprecated > 42 > future > with value 1`] = `2024-11-19T18:52:08.216Z`; - -exports[`date > deprecated > 42 > past > with only Date refDate 1`] = `2020-10-08T00:10:57.898Z`; - -exports[`date > deprecated > 42 > past > with only number refDate 1`] = `2020-10-08T00:10:57.898Z`; - -exports[`date > deprecated > 42 > past > with only string refDate 1`] = `2020-10-08T00:10:57.898Z`; - -exports[`date > deprecated > 42 > past > with value 1`] = `2017-05-26T15:26:23.206Z`; - -exports[`date > deprecated > 42 > recent > with only Date refDate 1`] = `2021-02-21T08:09:54.819Z`; - -exports[`date > deprecated > 42 > recent > with only number refDate 1`] = `2021-02-21T08:09:54.819Z`; - -exports[`date > deprecated > 42 > recent > with only string refDate 1`] = `2021-02-21T08:09:54.819Z`; - -exports[`date > deprecated > 42 > recent > with value 1`] = `2021-02-17T23:15:52.423Z`; - -exports[`date > deprecated > 42 > soon > with only Date refDate 1`] = `2021-02-22T02:08:36.603Z`; - -exports[`date > deprecated > 42 > soon > with only number refDate 1`] = `2021-02-22T02:08:36.603Z`; - -exports[`date > deprecated > 42 > soon > with only string refDate 1`] = `2021-02-22T02:08:36.603Z`; - -exports[`date > deprecated > 42 > soon > with value 1`] = `2021-02-25T11:02:38.999Z`; - -exports[`date > deprecated > 1211 > between > with Date dates 1`] = `2021-04-17T11:58:13.327Z`; - -exports[`date > deprecated > 1211 > between > with string dates 1`] = `2021-04-17T11:58:13.327Z`; - -exports[`date > deprecated > 1211 > betweens > with Date dates 1`] = ` -[ - 2021-03-07T00:34:12.745Z, - 2021-04-15T10:20:25.794Z, - 2021-04-17T11:58:13.327Z, -] -`; - -exports[`date > deprecated > 1211 > betweens > with Date dates and count 1`] = ` -[ - 2021-03-07T00:34:12.745Z, - 2021-04-02T08:42:57.721Z, - 2021-04-15T10:20:25.794Z, - 2021-04-17T11:58:13.327Z, - 2021-04-21T13:18:14.822Z, -] -`; - -exports[`date > deprecated > 1211 > betweens > with string dates 1`] = ` -[ - 2021-03-07T00:34:12.745Z, - 2021-04-15T10:20:25.794Z, - 2021-04-17T11:58:13.327Z, -] -`; - -exports[`date > deprecated > 1211 > betweens > with string dates and count 1`] = ` -[ - 2021-03-07T00:34:12.745Z, - 2021-04-02T08:42:57.721Z, - 2021-04-15T10:20:25.794Z, - 2021-04-17T11:58:13.327Z, - 2021-04-21T13:18:14.822Z, -] -`; - -exports[`date > deprecated > 1211 > future > with only Date refDate 1`] = `2022-01-26T14:59:27.356Z`; - -exports[`date > deprecated > 1211 > future > with only number refDate 1`] = `2022-01-26T14:59:27.356Z`; - -exports[`date > deprecated > 1211 > future > with only string refDate 1`] = `2022-01-26T14:59:27.356Z`; - -exports[`date > deprecated > 1211 > future > with value 1`] = `2030-06-03T19:31:11.518Z`; - -exports[`date > deprecated > 1211 > past > with only Date refDate 1`] = `2020-03-19T19:19:04.066Z`; - -exports[`date > deprecated > 1211 > past > with only number refDate 1`] = `2020-03-19T19:19:04.066Z`; - -exports[`date > deprecated > 1211 > past > with only string refDate 1`] = `2020-03-19T19:19:04.066Z`; - -exports[`date > deprecated > 1211 > past > with value 1`] = `2011-11-12T14:47:19.904Z`; - -exports[`date > deprecated > 1211 > recent > with only Date refDate 1`] = `2021-02-20T18:52:11.498Z`; - -exports[`date > deprecated > 1211 > recent > with only number refDate 1`] = `2021-02-20T18:52:11.498Z`; - -exports[`date > deprecated > 1211 > recent > with only string refDate 1`] = `2021-02-20T18:52:11.498Z`; - -exports[`date > deprecated > 1211 > recent > with value 1`] = `2021-02-12T10:18:34.226Z`; - -exports[`date > deprecated > 1211 > soon > with only Date refDate 1`] = `2021-02-22T15:26:19.924Z`; - -exports[`date > deprecated > 1211 > soon > with only number refDate 1`] = `2021-02-22T15:26:19.924Z`; - -exports[`date > deprecated > 1211 > soon > with only string refDate 1`] = `2021-02-22T15:26:19.924Z`; - -exports[`date > deprecated > 1211 > soon > with value 1`] = `2021-03-02T23:59:57.196Z`; - -exports[`date > deprecated > 1337 > between > with Date dates 1`] = `2021-03-09T04:11:24.661Z`; - -exports[`date > deprecated > 1337 > between > with string dates 1`] = `2021-03-09T04:11:24.661Z`; - -exports[`date > deprecated > 1337 > betweens > with Date dates 1`] = ` -[ - 2021-03-03T01:51:22.487Z, - 2021-03-09T04:11:24.661Z, - 2021-03-10T02:59:27.388Z, -] -`; - -exports[`date > deprecated > 1337 > betweens > with Date dates and count 1`] = ` -[ - 2021-03-03T01:51:22.487Z, - 2021-03-09T04:11:24.661Z, - 2021-03-10T02:59:27.388Z, - 2021-03-12T15:42:07.228Z, - 2021-03-20T19:33:45.512Z, -] -`; - -exports[`date > deprecated > 1337 > betweens > with string dates 1`] = ` -[ - 2021-03-03T01:51:22.487Z, - 2021-03-09T04:11:24.661Z, - 2021-03-10T02:59:27.388Z, -] -`; - -exports[`date > deprecated > 1337 > betweens > with string dates and count 1`] = ` -[ - 2021-03-03T01:51:22.487Z, - 2021-03-09T04:11:24.661Z, - 2021-03-10T02:59:27.388Z, - 2021-03-12T15:42:07.228Z, - 2021-03-20T19:33:45.512Z, -] -`; - -exports[`date > deprecated > 1337 > future > with only Date refDate 1`] = `2021-05-28T08:29:26.600Z`; - -exports[`date > deprecated > 1337 > future > with only number refDate 1`] = `2021-05-28T08:29:26.600Z`; - -exports[`date > deprecated > 1337 > future > with only string refDate 1`] = `2021-05-28T08:29:26.600Z`; - -exports[`date > deprecated > 1337 > future > with value 1`] = `2023-10-06T02:30:57.962Z`; - -exports[`date > deprecated > 1337 > past > with only Date refDate 1`] = `2020-11-18T01:49:04.822Z`; - -exports[`date > deprecated > 1337 > past > with only number refDate 1`] = `2020-11-18T01:49:04.822Z`; - -exports[`date > deprecated > 1337 > past > with only string refDate 1`] = `2020-11-18T01:49:04.822Z`; - -exports[`date > deprecated > 1337 > past > with value 1`] = `2018-07-11T07:47:33.460Z`; - -exports[`date > deprecated > 1337 > recent > with only Date refDate 1`] = `2021-02-21T10:51:56.041Z`; - -exports[`date > deprecated > 1337 > recent > with only number refDate 1`] = `2021-02-21T10:51:56.041Z`; - -exports[`date > deprecated > 1337 > recent > with only string refDate 1`] = `2021-02-21T10:51:56.041Z`; - -exports[`date > deprecated > 1337 > recent > with value 1`] = `2021-02-19T02:16:05.654Z`; - -exports[`date > deprecated > 1337 > soon > with only Date refDate 1`] = `2021-02-21T23:26:35.381Z`; - -exports[`date > deprecated > 1337 > soon > with only number refDate 1`] = `2021-02-21T23:26:35.381Z`; - -exports[`date > deprecated > 1337 > soon > with only string refDate 1`] = `2021-02-21T23:26:35.381Z`; - -exports[`date > deprecated > 1337 > soon > with value 1`] = `2021-02-24T08:02:25.768Z`; diff --git a/test/modules/date.spec.ts b/test/modules/date.spec.ts index d2e08337..303dc407 100644 --- a/test/modules/date.spec.ts +++ b/test/modules/date.spec.ts @@ -141,66 +141,6 @@ describe('date', () => { }); }); - describe('deprecated', () => { - seededTests(faker, 'date', (t) => { - t.describeEach( - 'past', - 'recent', - 'soon', - 'future' - )((t) => { - t.it('with only string refDate', undefined, refDate) - .it('with only Date refDate', undefined, new Date(refDate)) - .it( - 'with only number refDate', - undefined, - new Date(refDate).getTime() - ) - .it('with value', 10, refDate); - }); - - t.describe('between', (t) => { - t.it( - 'with string dates', - '2021-02-21T17:09:15.711Z', - '2021-04-21T17:11:17.711Z' - ).it( - 'with Date dates', - new Date('2021-02-21T17:09:15.711Z'), - new Date('2021-04-21T17:11:17.711Z') - ); - }); - - t.describe('betweens', (t) => { - t.it( - 'with string dates', - '2021-02-21T17:09:15.711Z', - '2021-04-21T17:11:17.711Z' - ) - .it( - 'with Date dates', - new Date('2021-02-21T17:09:15.711Z'), - new Date('2021-04-21T17:11:17.711Z') - ) - .it( - 'with string dates and count', - '2021-02-21T17:09:15.711Z', - '2021-04-21T17:11:17.711Z', - 5 - ) - .it( - 'with Date dates and count', - new Date('2021-02-21T17:09:15.711Z'), - new Date('2021-04-21T17:11:17.711Z'), - 5 - ); - }); - - // No changes to these methods - t.skip('anytime').skip('birthdate').skip('month').skip('weekday'); - }); - }); - describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( 'random seeded tests for seed %i', () => { @@ -325,11 +265,11 @@ describe('date', () => { const from = new Date(1990, 5, 7, 9, 11, 0, 0); const to = new Date(2000, 6, 8, 10, 12, 0, 0); - const dates = faker.date.betweens( - converter(from), - converter(to), - 2 - ); + const dates = faker.date.betweens({ + from: converter(from), + to: converter(to), + count: 2, + }); expect(dates).toHaveLength(2); @@ -458,22 +398,11 @@ describe('date', () => { expect(fakerAZ.definitions.date.month.wide_context).toContain(month); }); - it('should return random value from date.month.abbr array for abbr option', () => { - const month = faker.date.month({ abbr: true }); - expect(faker.definitions.date.month.abbr).toContain(month); - }); - it('should return random value from date.month.abbr array for abbreviated option', () => { const month = faker.date.month({ abbreviated: true }); expect(faker.definitions.date.month.abbr).toContain(month); }); - it('should return random value from date.month.abbr_context array for abbr and context option', () => { - // Use a locale (e.g. az) which has a wide_context array - const month = fakerAZ.date.month({ abbr: true, context: true }); - expect(fakerAZ.definitions.date.month.abbr_context).toContain(month); - }); - it('should return random value from date.month.abbr_context array for abbreviated and context option', () => { // Use a locale (e.g. az) which has a wide_context array const month = fakerAZ.date.month({ @@ -489,12 +418,6 @@ describe('date', () => { expect(faker.definitions.date.month.wide).toContain(month); }); - it('should return random value from date.month.abbr array for abbr and context option when date.month.abbr_context array is missing', () => { - // Use a locale (e.g. the default en) which has no abbr_context array - const month = faker.date.month({ abbr: true, context: true }); - expect(faker.definitions.date.month.abbr).toContain(month); - }); - it('should return random value from date.month.abbr array for abbreviated and context option when date.month.abbr_context array is missing', () => { // Use a locale (e.g. the default en) which has no abbr_context array const month = faker.date.month({ abbreviated: true, context: true }); @@ -516,24 +439,11 @@ describe('date', () => { ); }); - it('should return random value from date.weekday.abbr array for abbr option', () => { - const weekday = faker.date.weekday({ abbr: true }); - expect(faker.definitions.date.weekday.abbr).toContain(weekday); - }); - it('should return random value from date.weekday.abbr array for abbreviated option', () => { const weekday = faker.date.weekday({ abbreviated: true }); expect(faker.definitions.date.weekday.abbr).toContain(weekday); }); - it('should return random value from date.weekday.abbr_context array for abbr and context option', () => { - // Use a locale (e.g. az) which has a abbr_context array - const weekday = fakerAZ.date.weekday({ abbr: true, context: true }); - expect(fakerAZ.definitions.date.weekday.abbr_context).toContain( - weekday - ); - }); - it('should return random value from date.weekday.abbr_context array for abbreviated and context option', () => { // Use a locale (e.g. az) which has a abbr_context array const weekday = fakerAZ.date.weekday({ @@ -551,12 +461,6 @@ describe('date', () => { expect(faker.definitions.date.weekday.wide).toContain(weekday); }); - it('should return random value from date.weekday.abbr array for abbr and context option when date.weekday.abbr_context array is missing', () => { - // Use a locale (e.g. the default en) which has no abbr_context array - const weekday = faker.date.weekday({ abbr: true, context: true }); - expect(faker.definitions.date.weekday.abbr).toContain(weekday); - }); - it('should return random value from date.weekday.abbr array for abbreviated and context option when date.weekday.abbr_context array is missing', () => { // Use a locale (e.g. the default en) which has no abbr_context array const weekday = faker.date.weekday({ @@ -647,177 +551,6 @@ describe('date', () => { ); }); }); - - describe('deprecated', () => { - describe('past()', () => { - it('should return a date 5 years in the past', () => { - const today = new Date(); - const yearsAgo = new Date(today); - yearsAgo.setFullYear(yearsAgo.getFullYear() - 5); - - const date = faker.date.past(5); - - expect(date).lessThan(today); - expect(date).greaterThanOrEqual(yearsAgo); - }); - - it('should throw an error when years = 0', () => { - const refDate = new Date(); - expect(() => faker.date.past(0, refDate.toISOString())).toThrow( - new FakerError('Years must be greater than 0.') - ); - }); - - it.each(converterMap)( - 'should return a past date relative to given refDate', - (converter) => { - const refDate = new Date(); - refDate.setFullYear(refDate.getFullYear() + 5); - - const date = faker.date.past(5, converter(refDate)); - - expect(date).lessThan(refDate); - expect(date).greaterThan(new Date()); - } - ); - }); - - describe('future()', () => { - it('should return a date 75 years into the future', () => { - const date = faker.date.future(75); - - expect(date).greaterThan(new Date()); - }); - - it('should throw an error when years = 0', () => { - const refDate = new Date(); - expect(() => faker.date.future(0, refDate.toISOString())).toThrow( - new FakerError('Years must be greater than 0.') - ); - }); - - it.each(converterMap)( - 'should return a date 75 years after the date given', - (converter) => { - const refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly) - - const date = faker.date.future(75, converter(refDate)); - - // date should be after the date given, but before the current time - expect(date).greaterThan(refDate); - expect(date).lessThan(new Date()); - } - ); - }); - - describe('between()', () => { - it.each(converterMap)( - 'should return a random date between the dates given', - (converter) => { - const from = new Date(1990, 5, 7, 9, 11, 0, 0); - const to = new Date(2000, 6, 8, 10, 12, 0, 0); - - const date = faker.date.between(converter(from), converter(to)); - - expect(date).greaterThan(from); - expect(date).lessThan(to); - } - ); - }); - - describe('betweens()', () => { - it.each(converterMap)( - 'should return an array of 3 dates ( by default ) of sorted randoms dates between the dates given', - (converter) => { - const from = new Date(1990, 5, 7, 9, 11, 0, 0); - const to = new Date(2000, 6, 8, 10, 12, 0, 0); - - const dates = faker.date.betweens(converter(from), converter(to)); - - expect(dates[0]).greaterThan(from); - expect(dates[0]).lessThan(to); - expect(dates[1]).greaterThan(dates[0]); - expect(dates[2]).greaterThan(dates[1]); - } - ); - }); - - describe('recent()', () => { - it('should return a date N days from the recent past', () => { - const date = faker.date.recent(30); - - expect(date).lessThanOrEqual(new Date()); - }); - - it('should throw an error when days = 0', () => { - const refDate = new Date(); - expect(() => faker.date.recent(0, refDate.toISOString())).toThrow( - new FakerError('Days must be greater than 0.') - ); - }); - - it.each(converterMap)( - 'should return a date N days from the recent past, starting from refDate', - (converter) => { - const days = 30; - const refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly) - - const lowerBound = new Date( - refDate.getTime() - days * 24 * 60 * 60 * 1000 - ); - - const date = faker.date.recent(days, converter(refDate)); - - expect( - lowerBound, - '`recent()` date should not be further back than `n` days ago' - ).lessThanOrEqual(date); - expect( - date, - '`recent()` date should not be ahead of the starting date reference' - ).lessThanOrEqual(refDate); - } - ); - }); - - describe('soon()', () => { - it('should return a date N days into the future', () => { - const date = faker.date.soon(30); - - expect(date).greaterThanOrEqual(new Date()); - }); - - it('should throw an error when days = 0', () => { - const refDate = new Date(); - expect(() => faker.date.soon(0, refDate.toISOString())).toThrow( - new FakerError('Days must be greater than 0.') - ); - }); - - it.each(converterMap)( - 'should return a date N days from the recent future, starting from refDate', - (converter) => { - const days = 30; - const refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly) - - const upperBound = new Date( - refDate.getTime() + days * 24 * 60 * 60 * 1000 - ); - - const date = faker.date.soon(days, converter(refDate)); - - expect( - date, - '`soon()` date should not be further ahead than `n` days ago' - ).lessThanOrEqual(upperBound); - expect( - refDate, - '`soon()` date should not be behind the starting date reference' - ).lessThanOrEqual(date); - } - ); - }); - }); } ); |
