summaryrefslogtreecommitdiff
path: root/date-fns/src/startOfSecond/test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/startOfSecond/test.ts')
-rw-r--r--date-fns/src/startOfSecond/test.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/date-fns/src/startOfSecond/test.ts b/date-fns/src/startOfSecond/test.ts
new file mode 100644
index 0000000..a7444c1
--- /dev/null
+++ b/date-fns/src/startOfSecond/test.ts
@@ -0,0 +1,35 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+import startOfSecond from '.'
+
+describe('startOfSecond', function() {
+ it('returns the date with the time set to the first millisecond of a second', function() {
+ const date = new Date(2014, 11 /* Dec */, 1, 22, 15, 45, 400)
+ const result = startOfSecond(date)
+ assert.deepEqual(result, new Date(2014, 11 /* Dec */, 1, 22, 15, 45))
+ })
+
+ it('accepts a timestamp', function() {
+ const date = new Date(2014, 11 /* Dec */, 1, 22, 15, 45, 400).getTime()
+ const result = startOfSecond(date)
+ assert.deepEqual(result, new Date(2014, 11 /* Dec */, 1, 22, 15, 45))
+ })
+
+ it('does not mutate the original date', function() {
+ const date = new Date(2014, 11 /* Dec */, 1, 22, 15, 45, 400)
+ startOfSecond(date)
+ assert.deepEqual(date, new Date(2014, 11 /* Dec */, 1, 22, 15, 45, 400))
+ })
+
+ it('returns `Invalid Date` if the given date is invalid', function() {
+ const result = startOfSecond(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(startOfSecond.bind(null), TypeError)
+ })
+})