diff options
author | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:46:06 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:48:30 -0300 |
commit | 38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch) | |
tree | 453dbf70000cc5e338b06201af1eaca8343f8f73 /date-fns/src/endOfISOWeekYear/test.ts | |
parent | f26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff) | |
download | node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2 node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip |
Diffstat (limited to 'date-fns/src/endOfISOWeekYear/test.ts')
-rw-r--r-- | date-fns/src/endOfISOWeekYear/test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/date-fns/src/endOfISOWeekYear/test.ts b/date-fns/src/endOfISOWeekYear/test.ts new file mode 100644 index 0000000..5a155c9 --- /dev/null +++ b/date-fns/src/endOfISOWeekYear/test.ts @@ -0,0 +1,46 @@ +// @flow +/* eslint-env mocha */ + +import assert from 'power-assert' +import endOfISOWeekYear from '.' + +describe('endOfISOWeekYear', function() { + it('returns the date with the time set to 23:59:59.999 and the date set to the last day of an ISO year', function() { + const result = endOfISOWeekYear(new Date(2009, 0 /* Jan */, 1, 16, 0)) + assert.deepEqual(result, new Date(2010, 0 /* Jan */, 3, 23, 59, 59, 999)) + }) + + it('accepts a timestamp', function() { + const result = endOfISOWeekYear( + new Date(2005, 0 /* Jan */, 1, 6, 0).getTime() + ) + assert.deepEqual(result, new Date(2005, 0 /* Jan */, 2, 23, 59, 59, 999)) + }) + + it('does not mutate the original date', function() { + const date = new Date(2014, 6 /* Jul */, 2) + endOfISOWeekYear(date) + assert.deepEqual(date, new Date(2014, 6 /* Jul */, 2)) + }) + + it('handles dates before 100 AD', function() { + const initialDate = new Date(0) + initialDate.setFullYear(5, 0 /* Jan */, 4) + initialDate.setHours(16, 0, 0, 0) + const expectedResult = new Date(0) + expectedResult.setFullYear(6, 0 /* Jan */, 1) + expectedResult.setHours(23, 59, 59, 999) + const result = endOfISOWeekYear(initialDate) + assert.deepEqual(result, expectedResult) + }) + + it('returns `Invalid Date` if the given date is invalid', function() { + const result = endOfISOWeekYear(new Date(NaN)) + //@ts-expect-error + assert(result instanceof Date && isNaN(result)) + }) + + it('throws TypeError exception if passed less than 1 argument', function() { + assert.throws(endOfISOWeekYear.bind(null), TypeError) + }) +}) |