summaryrefslogtreecommitdiff
path: root/date-fns/src/addISOWeekYears/test.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-08-23 16:46:06 -0300
committerSebastian <sebasjm@gmail.com>2021-08-23 16:48:30 -0300
commit38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch)
tree453dbf70000cc5e338b06201af1eaca8343f8f73 /date-fns/src/addISOWeekYears/test.ts
parentf26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff)
downloadnode-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz
node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2
node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip
added web vendorsHEADmaster
Diffstat (limited to 'date-fns/src/addISOWeekYears/test.ts')
-rw-r--r--date-fns/src/addISOWeekYears/test.ts64
1 files changed, 64 insertions, 0 deletions
diff --git a/date-fns/src/addISOWeekYears/test.ts b/date-fns/src/addISOWeekYears/test.ts
new file mode 100644
index 0000000..a122d71
--- /dev/null
+++ b/date-fns/src/addISOWeekYears/test.ts
@@ -0,0 +1,64 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'assert'
+import addISOWeekYears from '.'
+
+describe('addISOWeekYears', function() {
+ it('adds the given number of ISO week-numbering years', function() {
+ const result = addISOWeekYears(new Date(2010, 6 /* Jul */, 2), 5)
+ assert.deepStrictEqual(result, new Date(2015, 5 /* Jun */, 26))
+ })
+
+ it('accepts a timestamp', function() {
+ const result = addISOWeekYears(new Date(2014, 8 /* Sep */, 1).getTime(), 12)
+ assert.deepStrictEqual(result, new Date(2026, 7 /* Aug */, 31))
+ })
+
+ it('converts a fractional number to an integer', function() {
+ const result = addISOWeekYears(new Date(2010, 6 /* Jul */, 2), 5.6)
+ assert.deepStrictEqual(result, new Date(2015, 5 /* Jun */, 26))
+ })
+
+ it('implicitly converts number arguments', function() {
+ // @ts-expect-error
+ const result = addISOWeekYears(new Date(2010, 6 /* Jul */, 2), '5')
+ assert.deepStrictEqual(result, new Date(2015, 5 /* Jun */, 26))
+ })
+
+ it('does not mutate the original date', function() {
+ const date = new Date(2014, 8 /* Sep */, 1)
+ addISOWeekYears(date, 12)
+ assert.deepStrictEqual(date, new Date(2014, 8 /* Sep */, 1))
+ })
+
+ it('handles dates before 100 AD', function() {
+ const initialDate = new Date(0)
+ initialDate.setFullYear(10, 6 /* Jul */, 2)
+ initialDate.setHours(0, 0, 0, 0)
+ const expectedResult = new Date(0)
+ expectedResult.setFullYear(15, 5 /* Jun */, 26)
+ expectedResult.setHours(0, 0, 0, 0)
+ const result = addISOWeekYears(initialDate, 5)
+ assert.deepStrictEqual(result, expectedResult)
+ })
+
+ it('returns `Invalid Date` if the given date is invalid', function() {
+ const result = addISOWeekYears(new Date(NaN), 5)
+ // @ts-expect-error
+ assert(result instanceof Date && isNaN(result))
+ })
+
+ it('returns `Invalid Date` if the given amount is NaN', function() {
+ const result = addISOWeekYears(new Date(2010, 6 /* Jul */, 2), NaN)
+ // @ts-expect-error
+ assert(result instanceof Date && isNaN(result))
+ })
+
+ it('throws TypeError exception if passed less than 2 arguments', function() {
+ // @ts-expect-error
+ assert.throws(addISOWeekYears.bind(null), TypeError)
+ // @ts-expect-error
+ assert.throws(addISOWeekYears.bind(null, 1), TypeError)
+ })
+})