-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
directive.test.ts
74 lines (66 loc) · 1.49 KB
/
directive.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
69
70
71
72
73
74
import { defineComponent } from 'vue-demi'
import type { VueWrapper } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import { vOnKeyStroke } from './directive'
import type { OnKeyStrokeOptions } from '.'
const App = defineComponent({
props: {
onUpdate: {
type: Function,
required: true,
},
options: {
type: Object,
required: false,
},
},
template: `<template>
<div v-if="options" v-on-key-stroke="[onUpdate, options]">Hello world!</div>
<div v-else v-on-key-stroke="onUpdate">Hello world!</div>
</template>
`,
})
describe('vOnKeyStroke', () => {
let onUpdate = vi.fn()
let wrapper: VueWrapper<any>
describe('given no options', () => {
beforeEach(() => {
onUpdate = vi.fn()
wrapper = mount(App, {
props: {
onUpdate,
},
global: {
directives: {
'on-key-stroke': vOnKeyStroke,
},
},
})
})
it('should be defined', () => {
expect(wrapper).toBeDefined()
})
})
describe('given options', () => {
beforeEach(() => {
onUpdate = vi.fn()
const options: OnKeyStrokeOptions = {
passive: false,
}
wrapper = mount(App, {
props: {
onUpdate,
options,
},
global: {
directives: {
'on-key-stroke': vOnKeyStroke,
},
},
})
})
it('should be defined', () => {
expect(wrapper).toBeDefined()
})
})
})