-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
test.js
57 lines (47 loc) · 2.09 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// @flow
/* eslint-env mocha */
import assert from 'power-assert'
import roundToNearestMinutes from '.'
describe('roundToNearestMinutes', function () {
it('rounds given date to the nearest minute', function () {
var result = roundToNearestMinutes(new Date(2014, 6 /* Jul */, 10, 12, 16, 16))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 16, 0))
})
it('accepts a string', function () {
var result = roundToNearestMinutes(
new Date(2014, 6 /* Jul */, 10, 12, 13, 16).toISOString()
)
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 13, 0))
})
it('accepts a timestamp', function () {
var result = roundToNearestMinutes(
new Date(2014, 6 /* Jul */, 10, 12, 13, 16).getTime()
)
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 13, 0))
})
it('rounds up 30 seconds and above', function () {
var result = roundToNearestMinutes(new Date(2014, 6 /* Jul */, 10, 12, 10, 30))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 11, 0))
})
it('rounds down <30 seconds', function () {
var result = roundToNearestMinutes(new Date(2014, 6 /* Jul */, 10, 12, 13, 29, 999))
assert.deepEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 13, 0))
})
it('does not mutate the original date', function () {
var date = new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99)
roundToNearestMinutes(date)
assert.deepEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99))
})
it('returns `Invalid Date` if the given date is invalid', function () {
var result = roundToNearestMinutes(new Date(NaN))
assert(result instanceof Date && isNaN(result))
})
it('throws `RangeError` if `options.additionalDigits` is not convertable to 0, 1, 2 or undefined`', function () {
// $ExpectedMistake
var block = roundToNearestMinutes.bind(null, new Date(2014, 6 /* Jul */, 10, 12, 10, 30), {additionalDigits: NaN})
assert.throws(block, RangeError)
})
it('throws TypeError exception if passed less than 1 argument', function () {
assert.throws(roundToNearestMinutes.bind(null), TypeError)
})
})