forked from date-fns/date-fns
/
test.ts
43 lines (38 loc) · 1.47 KB
/
test.ts
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
import assert from 'assert'
import clamp from '.'
describe('clamp', () => {
it('accepts timestamps', () => {
const start = new Date(2000, 1, 1).getTime()
const date = new Date(2000, 1, 2).getTime()
const end = new Date(2000, 1, 3).getTime()
const result = clamp(date, { start, end })
assert.deepStrictEqual(result, new Date(2000, 1, 2))
})
it('returns the start date when the date is less than start', () => {
const start = new Date(2001, 1, 1)
const date = new Date(2000, 1, 1)
const end = new Date(2020, 1, 1)
const result = clamp(date, { start, end })
assert.deepStrictEqual(result, new Date(2001, 1, 1))
})
it('returns the end date when the date is greater than the end date', () => {
const start = new Date(2000, 1, 1)
const date = new Date(2003, 1, 1)
const end = new Date(2001, 1, 1)
const result = clamp(date, { start, end })
assert.deepStrictEqual(result, new Date(2001, 1, 1))
})
it('returns the date when the date is within the bound of start and end', () => {
const start = new Date(2000, 1, 1)
const date = new Date(2001, 1, 1)
const end = new Date(2003, 1, 1)
const result = clamp(date, { start, end })
assert.deepStrictEqual(result, new Date(2001, 1, 1))
})
it('throws TypeError exception if passed less than 2 arguments', () => {
// @ts-expect-error
assert.throws(clamp.bind(null), TypeError)
// @ts-expect-error
assert.throws(clamp.bind(null, 1), TypeError)
})
})