summaryrefslogtreecommitdiff
path: root/date-fns/src/endOfQuarter/test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/endOfQuarter/test.ts')
-rw-r--r--date-fns/src/endOfQuarter/test.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/date-fns/src/endOfQuarter/test.ts b/date-fns/src/endOfQuarter/test.ts
new file mode 100644
index 0000000..11d2e5c
--- /dev/null
+++ b/date-fns/src/endOfQuarter/test.ts
@@ -0,0 +1,35 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+import endOfQuarter from '.'
+
+describe('endOfQuarter', function() {
+ it('returns the date with the time set to 23:59:59.999 and the date set to the last day of a quarter', function() {
+ const date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0)
+ const result = endOfQuarter(date)
+ assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999))
+ })
+
+ it('accepts a timestamp', function() {
+ const date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0).getTime()
+ const result = endOfQuarter(date)
+ assert.deepEqual(result, new Date(2014, 8 /* Sep */, 30, 23, 59, 59, 999))
+ })
+
+ it('does not mutate the original date', function() {
+ const date = new Date(2014, 8 /* Sep */, 2, 11, 55, 0)
+ endOfQuarter(date)
+ assert.deepEqual(date, new Date(2014, 8 /* Sep */, 2, 11, 55, 0))
+ })
+
+ it('returns `Invalid Date` if the given date is invalid', function() {
+ const result = endOfQuarter(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(endOfQuarter.bind(null), TypeError)
+ })
+})