@@ -30,18 +30,18 @@ describe('api: createApp', () => {
30
30
}
31
31
32
32
const root1 = nodeOps . createElement ( 'div' )
33
- createApp ( ) . mount ( Comp , root1 )
33
+ createApp ( Comp ) . mount ( root1 )
34
34
expect ( serializeInner ( root1 ) ) . toBe ( `0` )
35
35
36
36
// mount with props
37
37
const root2 = nodeOps . createElement ( 'div' )
38
- const app2 = createApp ( )
39
- app2 . mount ( Comp , root2 , { count : 1 } )
38
+ const app2 = createApp ( Comp , { count : 1 } )
39
+ app2 . mount ( root2 )
40
40
expect ( serializeInner ( root2 ) ) . toBe ( `1` )
41
41
42
42
// remount warning
43
43
const root3 = nodeOps . createElement ( 'div' )
44
- app2 . mount ( Comp , root3 )
44
+ app2 . mount ( root3 )
45
45
expect ( serializeInner ( root3 ) ) . toBe ( `` )
46
46
expect ( `already been mounted` ) . toHaveBeenWarned ( )
47
47
} )
@@ -59,18 +59,14 @@ describe('api: createApp', () => {
59
59
}
60
60
61
61
const root = nodeOps . createElement ( 'div' )
62
- const app = createApp ( )
63
- app . mount ( Comp , root )
62
+ const app = createApp ( Comp )
63
+ app . mount ( root )
64
64
65
65
app . unmount ( root )
66
66
expect ( serializeInner ( root ) ) . toBe ( `` )
67
67
} )
68
68
69
69
test ( 'provide' , ( ) => {
70
- const app = createApp ( )
71
- app . provide ( 'foo' , 1 )
72
- app . provide ( 'bar' , 2 )
73
-
74
70
const Root = {
75
71
setup ( ) {
76
72
// test override
@@ -87,25 +83,16 @@ describe('api: createApp', () => {
87
83
}
88
84
}
89
85
86
+ const app = createApp ( Root )
87
+ app . provide ( 'foo' , 1 )
88
+ app . provide ( 'bar' , 2 )
89
+
90
90
const root = nodeOps . createElement ( 'div' )
91
- app . mount ( Root , root )
91
+ app . mount ( root )
92
92
expect ( serializeInner ( root ) ) . toBe ( `3,2` )
93
93
} )
94
94
95
95
test ( 'component' , ( ) => {
96
- const app = createApp ( )
97
-
98
- const FooBar = ( ) => 'foobar!'
99
- app . component ( 'FooBar' , FooBar )
100
- expect ( app . component ( 'FooBar' ) ) . toBe ( FooBar )
101
-
102
- app . component ( 'BarBaz' , ( ) => 'barbaz!' )
103
-
104
- app . component ( 'BarBaz' , ( ) => 'barbaz!' )
105
- expect (
106
- 'Component "BarBaz" has already been registered in target app.'
107
- ) . toHaveBeenWarnedTimes ( 1 )
108
-
109
96
const Root = {
110
97
// local override
111
98
components : {
@@ -122,33 +109,29 @@ describe('api: createApp', () => {
122
109
}
123
110
}
124
111
112
+ const app = createApp ( Root )
113
+
114
+ const FooBar = ( ) => 'foobar!'
115
+ app . component ( 'FooBar' , FooBar )
116
+ expect ( app . component ( 'FooBar' ) ) . toBe ( FooBar )
117
+
118
+ app . component ( 'BarBaz' , ( ) => 'barbaz!' )
119
+
120
+ app . component ( 'BarBaz' , ( ) => 'barbaz!' )
121
+ expect (
122
+ 'Component "BarBaz" has already been registered in target app.'
123
+ ) . toHaveBeenWarnedTimes ( 1 )
124
+
125
125
const root = nodeOps . createElement ( 'div' )
126
- app . mount ( Root , root )
126
+ app . mount ( root )
127
127
expect ( serializeInner ( root ) ) . toBe ( `<div>foobar!barbaz-local!</div>` )
128
128
} )
129
129
130
130
test ( 'directive' , ( ) => {
131
- const app = createApp ( )
132
-
133
131
const spy1 = jest . fn ( )
134
132
const spy2 = jest . fn ( )
135
133
const spy3 = jest . fn ( )
136
134
137
- const FooBar = { mounted : spy1 }
138
- app . directive ( 'FooBar' , FooBar )
139
- expect ( app . directive ( 'FooBar' ) ) . toBe ( FooBar )
140
-
141
- app . directive ( 'BarBaz' , {
142
- mounted : spy2
143
- } )
144
-
145
- app . directive ( 'BarBaz' , {
146
- mounted : spy2
147
- } )
148
- expect (
149
- 'Directive "BarBaz" has already been registered in target app.'
150
- ) . toHaveBeenWarnedTimes ( 1 )
151
-
152
135
const Root = {
153
136
// local override
154
137
directives : {
@@ -165,8 +148,25 @@ describe('api: createApp', () => {
165
148
}
166
149
}
167
150
151
+ const app = createApp ( Root )
152
+
153
+ const FooBar = { mounted : spy1 }
154
+ app . directive ( 'FooBar' , FooBar )
155
+ expect ( app . directive ( 'FooBar' ) ) . toBe ( FooBar )
156
+
157
+ app . directive ( 'BarBaz' , {
158
+ mounted : spy2
159
+ } )
160
+
161
+ app . directive ( 'BarBaz' , {
162
+ mounted : spy2
163
+ } )
164
+ expect (
165
+ 'Directive "BarBaz" has already been registered in target app.'
166
+ ) . toHaveBeenWarnedTimes ( 1 )
167
+
168
168
const root = nodeOps . createElement ( 'div' )
169
- app . mount ( Root , root )
169
+ app . mount ( root )
170
170
expect ( spy1 ) . toHaveBeenCalled ( )
171
171
expect ( spy2 ) . not . toHaveBeenCalled ( )
172
172
expect ( spy3 ) . toHaveBeenCalled ( )
@@ -232,7 +232,7 @@ describe('api: createApp', () => {
232
232
}
233
233
}
234
234
235
- const app = createApp ( )
235
+ const app = createApp ( Comp )
236
236
app . mixin ( mixinA )
237
237
app . mixin ( mixinB )
238
238
@@ -246,7 +246,7 @@ describe('api: createApp', () => {
246
246
) . toHaveBeenWarnedTimes ( 1 )
247
247
248
248
const root = nodeOps . createElement ( 'div' )
249
- app . mount ( Comp , root )
249
+ app . mount ( root )
250
250
251
251
expect ( serializeInner ( root ) ) . toBe ( `123` )
252
252
expect ( calls ) . toEqual ( [
@@ -272,20 +272,21 @@ describe('api: createApp', () => {
272
272
}
273
273
const PluginD : any = undefined
274
274
275
- const app = createApp ( )
276
- app . use ( PluginA )
277
- app . use ( PluginB , 1 , 1 )
278
- app . use ( PluginC )
279
-
280
275
const Root = {
281
276
setup ( ) {
282
277
const foo = inject ( 'foo' )
283
278
const bar = inject ( 'bar' )
284
279
return ( ) => `${ foo } ,${ bar } `
285
280
}
286
281
}
282
+
283
+ const app = createApp ( Root )
284
+ app . use ( PluginA )
285
+ app . use ( PluginB , 1 , 1 )
286
+ app . use ( PluginC )
287
+
287
288
const root = nodeOps . createElement ( 'div' )
288
- app . mount ( Root , root )
289
+ app . mount ( root )
289
290
expect ( serializeInner ( root ) ) . toBe ( `1,2` )
290
291
291
292
app . use ( PluginA )
@@ -301,18 +302,14 @@ describe('api: createApp', () => {
301
302
} )
302
303
303
304
test ( 'config.errorHandler' , ( ) => {
304
- const app = createApp ( )
305
-
306
305
const error = new Error ( )
307
306
const count = ref ( 0 )
308
307
309
- const handler = ( app . config . errorHandler = jest . fn (
310
- ( err , instance , info ) => {
311
- expect ( err ) . toBe ( error )
312
- expect ( ( instance as any ) . count ) . toBe ( count . value )
313
- expect ( info ) . toBe ( `render function` )
314
- }
315
- ) )
308
+ const handler = jest . fn ( ( err , instance , info ) => {
309
+ expect ( err ) . toBe ( error )
310
+ expect ( ( instance as any ) . count ) . toBe ( count . value )
311
+ expect ( info ) . toBe ( `render function` )
312
+ } )
316
313
317
314
const Root = {
318
315
setup ( ) {
@@ -326,21 +323,19 @@ describe('api: createApp', () => {
326
323
}
327
324
}
328
325
329
- app . mount ( Root , nodeOps . createElement ( 'div' ) )
326
+ const app = createApp ( Root )
327
+ app . config . errorHandler = handler
328
+ app . mount ( nodeOps . createElement ( 'div' ) )
330
329
expect ( handler ) . toHaveBeenCalled ( )
331
330
} )
332
331
333
332
test ( 'config.warnHandler' , ( ) => {
334
- const app = createApp ( )
335
333
let ctx : any
336
-
337
- const handler = ( app . config . warnHandler = jest . fn (
338
- ( msg , instance , trace ) => {
339
- expect ( msg ) . toMatch ( `Component is missing template or render function` )
340
- expect ( instance ) . toBe ( ctx . proxy )
341
- expect ( trace ) . toMatch ( `Hello` )
342
- }
343
- ) )
334
+ const handler = jest . fn ( ( msg , instance , trace ) => {
335
+ expect ( msg ) . toMatch ( `Component is missing template or render function` )
336
+ expect ( instance ) . toBe ( ctx . proxy )
337
+ expect ( trace ) . toMatch ( `Hello` )
338
+ } )
344
339
345
340
const Root = {
346
341
name : 'Hello' ,
@@ -349,112 +344,92 @@ describe('api: createApp', () => {
349
344
}
350
345
}
351
346
352
- app . mount ( Root , nodeOps . createElement ( 'div' ) )
347
+ const app = createApp ( Root )
348
+ app . config . warnHandler = handler
349
+ app . mount ( nodeOps . createElement ( 'div' ) )
353
350
expect ( handler ) . toHaveBeenCalledTimes ( 1 )
354
351
} )
355
352
356
353
describe ( 'config.isNativeTag' , ( ) => {
357
354
const isNativeTag = jest . fn ( tag => tag === 'div' )
358
355
359
356
test ( 'Component.name' , ( ) => {
360
- const app = createApp ( )
361
- Object . defineProperty ( app . config , 'isNativeTag' , {
362
- value : isNativeTag ,
363
- writable : false
364
- } )
365
-
366
357
const Root = {
367
358
name : 'div' ,
368
- setup ( ) {
369
- return {
370
- count : ref ( 0 )
371
- }
372
- } ,
373
359
render ( ) {
374
360
return null
375
361
}
376
362
}
377
363
378
- app . mount ( Root , nodeOps . createElement ( 'div' ) )
379
- expect (
380
- `Do not use built-in or reserved HTML elements as component id: div`
381
- ) . toHaveBeenWarned ( )
382
- } )
364
+ const app = createApp ( Root )
383
365
384
- test ( 'Component.components' , ( ) => {
385
- const app = createApp ( )
386
366
Object . defineProperty ( app . config , 'isNativeTag' , {
387
367
value : isNativeTag ,
388
368
writable : false
389
369
} )
390
370
371
+ app . mount ( nodeOps . createElement ( 'div' ) )
372
+ expect (
373
+ `Do not use built-in or reserved HTML elements as component id: div`
374
+ ) . toHaveBeenWarned ( )
375
+ } )
376
+
377
+ test ( 'Component.components' , ( ) => {
391
378
const Root = {
392
379
components : {
393
380
div : ( ) => 'div'
394
381
} ,
395
- setup ( ) {
396
- return {
397
- count : ref ( 0 )
398
- }
399
- } ,
400
382
render ( ) {
401
383
return null
402
384
}
403
385
}
404
386
405
- app . mount ( Root , nodeOps . createElement ( 'div' ) )
387
+ const app = createApp ( Root )
388
+ Object . defineProperty ( app . config , 'isNativeTag' , {
389
+ value : isNativeTag ,
390
+ writable : false
391
+ } )
392
+
393
+ app . mount ( nodeOps . createElement ( 'div' ) )
406
394
expect (
407
395
`Do not use built-in or reserved HTML elements as component id: div`
408
396
) . toHaveBeenWarned ( )
409
397
} )
410
398
411
399
test ( 'Component.directives' , ( ) => {
412
- const app = createApp ( )
413
- Object . defineProperty ( app . config , 'isNativeTag' , {
414
- value : isNativeTag ,
415
- writable : false
416
- } )
417
-
418
400
const Root = {
419
401
directives : {
420
402
bind : ( ) => { }
421
403
} ,
422
- setup ( ) {
423
- return {
424
- count : ref ( 0 )
425
- }
426
- } ,
427
404
render ( ) {
428
405
return null
429
406
}
430
407
}
431
408
432
- app . mount ( Root , nodeOps . createElement ( 'div' ) )
409
+ const app = createApp ( Root )
410
+ Object . defineProperty ( app . config , 'isNativeTag' , {
411
+ value : isNativeTag ,
412
+ writable : false
413
+ } )
414
+
415
+ app . mount ( nodeOps . createElement ( 'div' ) )
433
416
expect (
434
417
`Do not use built-in directive ids as custom directive id: bind`
435
418
) . toHaveBeenWarned ( )
436
419
} )
437
420
438
421
test ( 'register using app.component' , ( ) => {
439
- const app = createApp ( )
422
+ const app = createApp ( {
423
+ render ( ) { }
424
+ } )
425
+
440
426
Object . defineProperty ( app . config , 'isNativeTag' , {
441
427
value : isNativeTag ,
442
428
writable : false
443
429
} )
444
430
445
- const Root = {
446
- setup ( ) {
447
- return {
448
- count : ref ( 0 )
449
- }
450
- } ,
451
- render ( ) {
452
- return null
453
- }
454
- }
455
-
456
431
app . component ( 'div' , ( ) => 'div' )
457
- app . mount ( Root , nodeOps . createElement ( 'div' ) )
432
+ app . mount ( nodeOps . createElement ( 'div' ) )
458
433
expect (
459
434
`Do not use built-in or reserved HTML elements as component id: div`
460
435
) . toHaveBeenWarned ( )
0 commit comments