forked from vuejs/test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompat.spec.ts
150 lines (120 loc) · 3.71 KB
/
compat.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import * as Vue from '@vue/compat'
import { mount } from '../src'
const { configureCompat, extend, defineComponent, h, config } = Vue as any
describe('@vue/compat build', () => {
beforeAll(() => {
config.compilerOptions.whitespace = 'condense'
})
describe.each(['suppress-warning', false])(
'when RENDER_FUNCTION compat is %p',
(RENDER_FUNCTION) => {
beforeEach(() => {
configureCompat({ MODE: 3, RENDER_FUNCTION })
})
it('renders default slot content when renderStubDefaultSlot is true', () => {
const Foo = { template: '<div><slot></slot></div>' }
const Component = {
components: { Foo },
template: '<foo>test</foo>'
}
const wrapper = mount(Component, {
global: {
stubs: { Foo: true },
renderStubDefaultSlot: true
}
})
expect(wrapper.html()).toBe('<foo-stub>test</foo-stub>')
})
it('correctly renders transition', () => {
const Component = defineComponent({
template: '<transition><div class="hello"></div></transition>'
})
const wrapper = mount(Component)
expect(wrapper.find('.hello').exists()).toBe(true)
})
}
)
it('finds components declared with legacy Vue.extend', () => {
configureCompat({ MODE: 3, GLOBAL_EXTEND: 'suppress-warning' })
const LegacyComponent = extend({
template: '<div>LEGACY</div>'
})
const Component = defineComponent({
components: {
LegacyComponent
},
template: '<div><legacy-component /></div>'
})
const wrapper = mount(Component)
expect(wrapper.findComponent(LegacyComponent).exists()).toBe(true)
})
it('correctly mounts legacy functional component', () => {
configureCompat({ MODE: 3, COMPONENT_FUNCTIONAL: 'suppress-warning' })
const Component = defineComponent({
functional: true,
render: () => h('div', 'test')
})
const wrapper = mount(Component)
expect(wrapper.html()).toBe('<div>test</div>')
})
it('does not stub root legacy functional component when shallow', () => {
configureCompat({
MODE: 3,
GLOBAL_EXTEND: 'suppress-warning',
COMPONENT_FUNCTIONAL: 'suppress-warning'
})
const Foo = {
name: 'Foo',
functional: true,
render: () => h('div', 'test')
}
const wrapper = mount(Foo, { shallow: true })
expect(wrapper.html()).toBe('<div>test</div>')
})
it('correctly mounts legacy functional component wrapped in Vue.extend', () => {
configureCompat({
MODE: 3,
GLOBAL_EXTEND: 'suppress-warning',
COMPONENT_FUNCTIONAL: 'suppress-warning'
})
const Component = extend({
functional: true,
render: () => h('div', 'test')
})
const wrapper = mount(Component)
expect(wrapper.html()).toBe('<div>test</div>')
})
it('correctly stubs legacy component wrapped in Vue.extend', () => {
configureCompat({
MODE: 3,
GLOBAL_EXTEND: 'suppress-warning'
})
const Foo = extend({
name: 'Foo',
template: '<div>original</div>'
})
const FooStub = { template: '<div>stubbed</div>' }
const Component = {
components: { NamedAsNotFoo: Foo },
template: '<named-as-not-foo />'
}
const wrapper = mount(Component, {
global: {
stubs: {
Foo: FooStub
}
}
})
expect(wrapper.html()).toBe('<div>stubbed</div>')
})
it('wrapper.vm points to correct instance when component is wrapped with Vue.extend', () => {
const Component = extend({
data() {
return { foo: 'bar' }
},
template: '<div></div>'
})
const wrapper = mount(Component)
expect(wrapper.vm.foo).toBe('bar')
})
})