1
+ import 'jsdom-global/register'
1
2
import test from 'ava'
2
- require ( 'jsdom-global' ) ( )
3
- const { shallow } = require ( 'vue-test-utils' )
3
+ import { shallowMount } from '@vue/test-utils'
4
+ import Vue from 'vue'
4
5
5
6
const it = ( ) => { }
6
7
7
8
test ( 'Contains text' , t => {
8
- const wrapper = shallow ( {
9
+ const wrapper = shallowMount ( {
9
10
render ( h ) {
10
11
return < div > test</ div >
11
12
} ,
@@ -17,7 +18,7 @@ test('Contains text', t => {
17
18
18
19
test ( 'Binds text' , t => {
19
20
const text = 'foo'
20
- const wrapper = shallow ( {
21
+ const wrapper = shallowMount ( {
21
22
render ( h ) {
22
23
return < div > { text } </ div >
23
24
} ,
@@ -28,7 +29,7 @@ test('Binds text', t => {
28
29
} )
29
30
30
31
test ( 'Extracts attrs' , t => {
31
- const wrapper = shallow ( {
32
+ const wrapper = shallowMount ( {
32
33
render ( h ) {
33
34
return < div id = "hi" dir = "ltr" />
34
35
} ,
@@ -40,7 +41,7 @@ test('Extracts attrs', t => {
40
41
41
42
test ( 'Binds attrs' , t => {
42
43
const id = 'foo'
43
- const wrapper = shallow ( {
44
+ const wrapper = shallowMount ( {
44
45
render ( h ) {
45
46
return < div id = { id } />
46
47
} ,
@@ -50,7 +51,7 @@ test('Binds attrs', t => {
50
51
} )
51
52
52
53
test ( 'Omits attrs if possible' , t => {
53
- const wrapper = shallow ( {
54
+ const wrapper = shallowMount ( {
54
55
render ( h ) {
55
56
return < div > test</ div >
56
57
} ,
@@ -60,7 +61,7 @@ test('Omits attrs if possible', t => {
60
61
} )
61
62
62
63
test ( 'Omits children if possible' , t => {
63
- const wrapper = shallow ( {
64
+ const wrapper = shallowMount ( {
64
65
render ( h ) {
65
66
return < div />
66
67
} ,
@@ -70,7 +71,7 @@ test('Omits children if possible', t => {
70
71
} )
71
72
72
73
test ( 'Handles top-level special attrs' , t => {
73
- const wrapper = shallow ( {
74
+ const wrapper = shallowMount ( {
74
75
render ( h ) {
75
76
return < div class = "foo" style = "bar" key = "key" ref = "ref" refInFor slot = "slot" />
76
77
} ,
@@ -85,7 +86,7 @@ test('Handles top-level special attrs', t => {
85
86
86
87
test ( 'Handles nested properties' , t => {
87
88
const noop = _ => _
88
- const wrapper = shallow ( {
89
+ const wrapper = shallowMount ( {
89
90
render ( h ) {
90
91
return (
91
92
< div
@@ -107,7 +108,7 @@ test('Handles nested properties', t => {
107
108
108
109
test ( 'Handles nested properties (camelCase)' , t => {
109
110
const noop = _ => _
110
- const wrapper = shallow ( {
111
+ const wrapper = shallowMount ( {
111
112
render ( h ) {
112
113
return (
113
114
< div propsOnSuccess = { noop } onClick = { noop } onCamelCase = { noop } domPropsInnerHTML = "<p>hi</p>" hookInsert = { noop } />
@@ -122,7 +123,7 @@ test('Handles nested properties (camelCase)', t => {
122
123
} )
123
124
124
125
test ( 'Supports data attribute' , t => {
125
- const wrapper = shallow ( {
126
+ const wrapper = shallowMount ( {
126
127
render ( h ) {
127
128
return < div data-id = "1" />
128
129
} ,
@@ -132,8 +133,8 @@ test('Supports data attribute', t => {
132
133
} )
133
134
134
135
test ( 'Handles identifier tag name as components' , t => {
135
- const Test = { }
136
- const wrapper = shallow ( {
136
+ const Test = { render : ( ) => null }
137
+ const wrapper = shallowMount ( {
137
138
render ( h ) {
138
139
return < Test />
139
140
} ,
@@ -143,8 +144,12 @@ test('Handles identifier tag name as components', t => {
143
144
} )
144
145
145
146
test ( 'Works for components with children' , t => {
146
- const Test = { }
147
- const wrapper = shallow ( {
147
+ const Test = {
148
+ render ( h ) {
149
+ h ( 'div' )
150
+ } ,
151
+ }
152
+ const wrapper = shallowMount ( {
148
153
render ( h ) {
149
154
return (
150
155
< Test >
@@ -164,7 +169,7 @@ test('Binds things in thunk with correct this context', t => {
164
169
return < div > { this . $slots . default } </ div >
165
170
} ,
166
171
}
167
- const wrapper = shallow ( {
172
+ const wrapper = shallowMount ( {
168
173
data : ( ) => ( { test : 'foo' } ) ,
169
174
render ( h ) {
170
175
return < Test > { this . test } </ Test >
@@ -178,7 +183,7 @@ test('Spread (single object expression)', t => {
178
183
const props = {
179
184
innerHTML : 2 ,
180
185
}
181
- const wrapper = shallow ( {
186
+ const wrapper = shallowMount ( {
182
187
render ( h ) {
183
188
return < div { ...{ props } } />
184
189
} ,
@@ -208,7 +213,7 @@ test('Spread (mixed)', t => {
208
213
} ,
209
214
class : [ 'a' , 'b' ] ,
210
215
}
211
- const wrapper = shallow ( {
216
+ const wrapper = shallowMount ( {
212
217
render ( h ) {
213
218
return (
214
219
< div
@@ -232,19 +237,25 @@ test('Spread (mixed)', t => {
232
237
} )
233
238
234
239
test ( 'Custom directives' , t => {
235
- const wrapper = shallow ( {
240
+ const directive = {
241
+ inserted ( ) { } ,
242
+ }
243
+ Vue . directive ( 'test' , directive )
244
+ Vue . directive ( 'other' , directive )
245
+
246
+ const wrapper = shallowMount ( {
236
247
render ( h ) {
237
248
return < div v-test = { 123 } vOther = { 234 } />
238
249
} ,
239
250
} )
240
251
241
252
t . is ( wrapper . vnode . data . directives . length , 2 )
242
- t . deepEqual ( wrapper . vnode . data . directives [ 0 ] , { def : undefined , modifiers : { } , name : 'test' , value : 123 } )
243
- t . deepEqual ( wrapper . vnode . data . directives [ 1 ] , { def : undefined , modifiers : { } , name : 'other' , value : 234 } )
253
+ t . deepEqual ( wrapper . vnode . data . directives [ 0 ] , { def : directive , modifiers : { } , name : 'test' , value : 123 } )
254
+ t . deepEqual ( wrapper . vnode . data . directives [ 1 ] , { def : directive , modifiers : { } , name : 'other' , value : 234 } )
244
255
} )
245
256
246
257
test ( 'xlink:href' , t => {
247
- const wrapper = shallow ( {
258
+ const wrapper = shallowMount ( {
248
259
render ( h ) {
249
260
return < use xlinkHref = { '#name' } />
250
261
} ,
@@ -254,7 +265,7 @@ test('xlink:href', t => {
254
265
} )
255
266
256
267
test ( 'Merge class' , t => {
257
- const wrapper = shallow ( {
268
+ const wrapper = shallowMount ( {
258
269
render ( h ) {
259
270
return < div class = "a" { ...{ class : 'b' } } />
260
271
} ,
@@ -273,7 +284,7 @@ test('JSXMemberExpression', t => {
273
284
} ,
274
285
} ,
275
286
}
276
- const wrapper = shallow ( {
287
+ const wrapper = shallowMount ( {
277
288
render ( h ) {
278
289
return < a . b . cmp />
279
290
} ,
@@ -284,7 +295,7 @@ test('JSXMemberExpression', t => {
284
295
285
296
test ( 'JSXSpreadChild' , t => {
286
297
const a = [ '1' , '2' ]
287
- const wrapper = shallow ( {
298
+ const wrapper = shallowMount ( {
288
299
render ( h ) {
289
300
return < div > { ...a } </ div >
290
301
} ,
@@ -295,7 +306,7 @@ test('JSXSpreadChild', t => {
295
306
296
307
test ( 'domProps input[value]' , t => {
297
308
const val = 'foo'
298
- const wrapper = shallow ( {
309
+ const wrapper = shallowMount ( {
299
310
render ( h ) {
300
311
return < input type = "text" value = { val } />
301
312
} ,
@@ -307,7 +318,7 @@ test('domProps input[value]', t => {
307
318
308
319
test ( 'domProps option[selected]' , t => {
309
320
const val = 'foo'
310
- const wrapper = shallow ( {
321
+ const wrapper = shallowMount ( {
311
322
render ( h ) {
312
323
return < option selected = { val } />
313
324
} ,
@@ -318,7 +329,7 @@ test('domProps option[selected]', t => {
318
329
319
330
test ( 'domProps input[checked]' , t => {
320
331
const val = 'foo'
321
- const wrapper = shallow ( {
332
+ const wrapper = shallowMount ( {
322
333
render ( h ) {
323
334
return < input checked = { val } />
324
335
} ,
@@ -329,7 +340,7 @@ test('domProps input[checked]', t => {
329
340
330
341
test ( 'domProps video[muted]' , t => {
331
342
const val = 'foo'
332
- const wrapper = shallow ( {
343
+ const wrapper = shallowMount ( {
333
344
render ( h ) {
334
345
return < video muted = { val } />
335
346
} ,
0 commit comments