/
menuable.spec.ts
70 lines (60 loc) 路 1.46 KB
/
menuable.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
import Menuable from '../'
import {
mount,
MountOptions,
Wrapper
} from '@vue/test-utils'
describe('menuable.ts', () => {
const Mock = Menuable.extend({
render: h => h('div')
})
type Instance = InstanceType<typeof Mock>
let mountFunction: (options?: MountOptions<Instance>) => Wrapper<Instance>
beforeEach(() => {
mountFunction = (options?: MountOptions<Instance>) => {
return mount(Mock, options)
}
})
it('should bind custom activator', () => {
const wrapper = mountFunction({
attachToDocument: true,
propsData: {
activator: 'body'
}
})
expect(wrapper.vm.getActivator()).toBeTruthy()
})
it('should update dimensions when activated', async () => {
const sneakPeek = jest.fn()
const wrapper = mountFunction({
methods: {
sneakPeek
}
})
wrapper.vm.updateDimensions()
await wrapper.vm.$nextTick()
expect(sneakPeek).toHaveBeenCalled()
})
it('should apply maxWidth in left calculations when offset', async () => {
const wrapper = mountFunction({
props: {
offsetY: Boolean,
offsetX: Boolean
},
propsData: {
attach: true,
left: true,
offsetX: true,
maxWidth: 200
}
})
wrapper.setData({
dimensions: {
activator: { width: 300 },
content: { width: 138 }
}
})
await wrapper.vm.$nextTick()
expect(wrapper.vm.computedLeft).toBe(-200)
})
})