/
times.spec.ts
79 lines (69 loc) 路 2.05 KB
/
times.spec.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
69
70
71
72
73
74
75
76
77
78
79
import Times from '../times'
import {
mount,
MountOptions,
Wrapper,
} from '@vue/test-utils'
import { ExtractVue } from '../../../../util/mixins'
import { CalendarTimestamp } from 'vuetify/types'
const Mock = Times.extend({
render: h => h('div'),
})
describe('times.ts', () => {
type Instance = ExtractVue<typeof Mock>
let mountFunction: (options?: MountOptions<Instance>) => Wrapper<Instance>
beforeEach(() => {
mountFunction = (options?: MountOptions<Instance>) => {
return mount(Mock, options)
}
})
it('should parse timestamp', async () => {
const wrapper = mountFunction({
propsData: {
now: '2019-02-08',
},
})
expect(wrapper.vm.parsedNow).toBeDefined()
expect(wrapper.vm.parsedNow).toMatchSnapshot()
})
it('should update day', async () => {
const wrapper = mountFunction()
expect(typeof wrapper.vm.updateDay).toBe('function')
const target = {}
const now = {
date: '2019-02-08',
year: '2019',
month: '2',
day: '8',
weekday: '4',
}
wrapper.vm.updateDay(now as unknown as CalendarTimestamp, target as unknown as CalendarTimestamp)
expect(target).toEqual(now)
})
it('should not update day if dates are equal', async () => {
const wrapper = mountFunction()
expect(typeof wrapper.vm.updateDay).toBe('function')
const target = { date: '2019-02-08' }
const now = {
date: '2019-02-08',
year: '2019',
month: '2',
day: '8',
weekday: '4',
}
wrapper.vm.updateDay(now as unknown as CalendarTimestamp, target as unknown as CalendarTimestamp)
expect(target).not.toEqual(now)
})
it('should not update time if times are equal', async () => {
const wrapper = mountFunction()
expect(typeof wrapper.vm.updateTime).toBe('function')
const target = { time: '08:30' }
const now = {
time: '08:30',
hour: '8',
minute: '30',
}
wrapper.vm.updateTime(now as unknown as CalendarTimestamp, target as unknown as CalendarTimestamp)
expect(target).not.toEqual(now)
})
})