-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
68 lines (51 loc) · 1.83 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts'
import miniDate from './mod.ts'
const { test } = Deno
const TIME = 'T12:00:00.000Z'
// miniDate on the 5th of November 2020
window.Date.now = () => Date.UTC(2020, 10, 5, 12)
test('Date.now() is overridden', () => {
assertEquals(1604577600000, Date.now())
})
test('current date is the 5th of November 2020', () => {
const subject = miniDate()
assertEquals(`2020-11-05${TIME}`, subject.toISOString())
})
test('it accepts day as number', () => {
const subject = miniDate(1)
assertEquals(`2020-11-01${TIME}`, subject.toISOString())
})
test('it accepts DD', () => {
const subject = miniDate('01')
assertEquals(`2020-11-01${TIME}`, subject.toISOString())
})
test('it accepts D-M', () => {
const subject = miniDate('1-1')
assertEquals(`2020-01-01${TIME}`, subject.toISOString())
})
test('it accepts D-MM-YYYY', () => {
const subject = miniDate('1-01-2019')
assertEquals(`2019-01-01${TIME}`, subject.toISOString())
})
test('it accepts falsy values', () => {
let subject = miniDate()
assertEquals(`2020-11-05${TIME}`, subject.toISOString())
subject = miniDate('')
assertEquals(`2020-11-05${TIME}`, subject.toISOString())
subject = miniDate(0)
assertEquals(`2020-11-05${TIME}`, subject.toISOString())
})
test('it simply gives back `Invalid Date` on wrong inputs', () => {
let subject = miniDate(32)
assertEquals('Invalid Date', subject.toString())
subject = miniDate('2020')
assertEquals('Invalid Date', subject.toString())
subject = miniDate('2020-13-')
assertEquals('Invalid Date', subject.toString())
subject = miniDate('-13-')
assertEquals('Invalid Date', subject.toString())
subject = miniDate('-13-')
assertEquals('Invalid Date', subject.toString())
subject = miniDate('-')
assertEquals('Invalid Date', subject.toString())
})