@@ -68,18 +68,21 @@ document.body.innerHTML = `
68
68
< / div >
69
69
`
70
70
71
+ const Component = {
72
+ template: ` < p > Vue Component < / p > `
73
+ }
74
+
71
75
test('mounts on a specific element', () => {
72
76
const wrapper = mount(Component, {
73
77
attachTo: document.getElementById('app')
74
78
})
75
79
76
- console.log(document.body.innerHTML)
77
- /*
78
- * <div>
79
- * <h1>Non Vue app</h1>
80
- * <div>Vue Component</div>
81
- * </div>
82
- */
80
+ expect(document.body.innerHTML).toBe( `
81
+ <div >
82
+ <h1 >Non Vue app < / h1 >
83
+ < div id = " app" > <div data -v -app =" " ><p >Vue Component < / p></ div > </div >
84
+ < / div >
85
+ ` )
83
86
})
84
87
` ` `
85
88
@@ -96,7 +99,7 @@ attrs?: Record<string, unknown>
96
99
** Details :**
97
100
98
101
` ` ` js
99
- test('assigns attributes ', () => {
102
+ test('attrs ', () => {
100
103
const wrapper = mount(Component, {
101
104
attrs: {
102
105
id: 'hello',
@@ -111,7 +114,7 @@ test('assigns attributes', () => {
111
114
})
112
115
` ` `
113
116
114
- Notice that setting a prop will always trump an attribute :
117
+ Notice that setting a defined prop will always trump an attribute :
115
118
116
119
` ` ` js
117
120
test('attribute is overridden by a prop with the same name', () => {
@@ -145,14 +148,14 @@ data?: () => {} extends Data ? any : Data extends object ? Partial<Data> : any
145
148
146
149
` ` ` vue
147
150
<template>
148
- <div>Foo is {{ foo }}</div>
151
+ <div>Hello {{ message }}</div>
149
152
</template>
150
153
151
154
<script>
152
155
export default {
153
156
data() {
154
157
return {
155
- foo : 'foo '
158
+ message : 'everyone '
156
159
}
157
160
}
158
161
}
@@ -162,16 +165,16 @@ export default {
162
165
` Component.spec.js ` :
163
166
164
167
` ` ` js
165
- test('overrides data', () => {
168
+ test('data', () => {
166
169
const wrapper = mount(Component, {
167
170
data() {
168
171
return {
169
- foo : 'bar '
172
+ message : 'world '
170
173
}
171
174
}
172
175
})
173
176
174
- expect(wrapper.html()).toContain('Foo is bar ')
177
+ expect(wrapper.html()).toContain('Hello world ')
175
178
})
176
179
` ` `
177
180
@@ -234,15 +237,15 @@ slots?: { [key: string]: Slot } & { default?: Slot }
234
237
235
238
** Details :**
236
239
237
- Slots can be a component imported from a ` .vue ` file or a render function . Currently providing an object with a `template` key is not supported.
240
+ Slots can be a string , a component imported from a ` .vue ` file or a render function . Currently providing an object with a `template` key is not supported.
238
241
239
242
`Component.vue`:
240
243
241
244
```vue
242
245
<template >
243
- <slot name = " foo " />
246
+ <slot name = " first " />
244
247
<slot />
245
- <slot name = " bar " />
248
+ <slot name = " second " />
246
249
</template >
247
250
```
248
251
@@ -255,13 +258,12 @@ test('renders slots content', () => {
255
258
const wrapper = mount (Component , {
256
259
slots: {
257
260
default: ' Default' ,
258
- foo : h (' h1' , {}, ' Named Slot' ),
259
- bar : Bar
261
+ first : h (' h1' , {}, ' Named Slot' ),
262
+ second : Bar
260
263
}
261
264
})
262
265
263
- console .log (wrapper .html ())
264
- // logs '<h1>Named Slot</h1>Default<div>Bar</div>'
266
+ expect(wrapper.html()).toBe(' <h1>Named Slot</h1>Default<div>Bar</div>' )
265
267
})
266
268
```
267
269
0 commit comments