-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
/
Copy pathcomponentFunctional.spec.ts
97 lines (88 loc) · 2.41 KB
/
componentFunctional.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Vue from '@vue/compat'
import {
DeprecationTypes,
deprecationData,
toggleDeprecationWarning,
} from '../../runtime-core/src/compat/compatConfig'
beforeEach(() => {
toggleDeprecationWarning(true)
Vue.configureCompat({
MODE: 2,
GLOBAL_MOUNT: 'suppress-warning',
})
})
afterEach(() => {
toggleDeprecationWarning(false)
Vue.configureCompat({ MODE: 3 })
})
describe('COMPONENT_FUNCTIONAL', () => {
test('basic usage', async () => {
const func = {
name: 'Func',
functional: true,
props: {
x: String,
},
inject: ['foo'],
render: (h: any, { data, props, injections, slots }: any) => {
return h('div', { id: props.x, class: data.class }, [
h('div', { class: 'inject' }, injections.foo),
h('div', { class: 'slot' }, slots().default),
])
},
}
const vm = new Vue({
provide() {
return {
foo: 123,
}
},
components: {
func,
},
template: `<func class="foo" x="foo">hello</func>`,
}).$mount()
expect(vm.$el.id).toBe('foo')
expect(vm.$el.className).toBe('foo')
expect(vm.$el.querySelector('.inject').textContent).toBe('123')
expect(vm.$el.querySelector('.slot').textContent).toBe('hello')
expect(vm.$el.outerHTML).toMatchInlineSnapshot(
`"<div id="foo" class="foo"><div class="inject">123</div><div class="slot">hello</div></div>"`,
)
expect(
(
deprecationData[DeprecationTypes.COMPONENT_FUNCTIONAL]
.message as Function
)(func),
).toHaveBeenWarned()
})
test('copies compatConfig option', () => {
const func = {
name: 'Func',
functional: true,
compatConfig: {
ATTR_FALSE_VALUE: 'suppress-warning' as const,
},
render: (h: any) => {
// should not render required: false due to compatConfig
return h('div', { 'data-some-attr': false })
},
}
const vm = new Vue({
components: { func },
template: `<func class="foo" x="foo">hello</func>`,
}).$mount()
expect(vm.$el.outerHTML).toMatchInlineSnapshot(`"<div></div>"`)
expect(
(
deprecationData[DeprecationTypes.COMPONENT_FUNCTIONAL]
.message as Function
)(func),
).toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
func,
),
).not.toHaveBeenWarned()
})
})