File tree Expand file tree Collapse file tree 4 files changed +43
-18
lines changed Expand file tree Collapse file tree 4 files changed +43
-18
lines changed Original file line number Diff line number Diff line change @@ -137,8 +137,10 @@ mount(Component, {
137
137
}
138
138
})
139
139
```
140
-
141
- ### ` mixins `
140
+ ### Global
141
+ You can provide properties to the App instance using the properties under the ` global ` mount property
142
+
143
+ ### ` global.mixins `
142
144
143
145
Applies mixins via ` app.mixin(...) ` .
144
146
@@ -161,14 +163,16 @@ test('adds a lifecycle mixin', () => {
161
163
}
162
164
163
165
const wrapper = mount (Component, {
164
- mixins: [mixin]
166
+ global: {
167
+ mixins: [mixin]
168
+ }
165
169
})
166
170
167
171
// 'Component was created!' will be logged
168
172
})
169
173
```
170
174
171
- ### ` plugins `
175
+ ### ` global. plugins`
172
176
173
177
Installs plugins on the component.
174
178
@@ -194,7 +198,9 @@ test('installs a plugin via `plugins`', () => {
194
198
render () { return h (' div' ) }
195
199
}
196
200
mount (Component, {
197
- plugins: [Plugin ]
201
+ global: {
202
+ plugins: [Plugin ]
203
+ }
198
204
})
199
205
200
206
expect (installed).toHaveBeenCalled ()
Original file line number Diff line number Diff line change 1
- import { h , createApp , VNode , defineComponent } from 'vue'
1
+ import {
2
+ h ,
3
+ createApp ,
4
+ VNode ,
5
+ defineComponent ,
6
+ Plugin ,
7
+ ComponentOptions
8
+ } from 'vue'
2
9
3
10
import { VueWrapper , createWrapper } from './vue-wrapper'
4
11
import { createEmitMixin } from './emitMixin'
@@ -13,8 +20,10 @@ interface MountingOptions<Props> {
13
20
default ?: Slot
14
21
[ key : string ] : Slot
15
22
}
16
- plugins ?: any [ ]
17
- mixins ?: any [ ]
23
+ global ?: {
24
+ plugins ?: Plugin [ ]
25
+ mixins ?: ComponentOptions [ ]
26
+ }
18
27
provides ?: Record < any , any >
19
28
stubs ?: Record < string , any >
20
29
}
@@ -59,13 +68,13 @@ export function mount<P>(
59
68
const vm = createApp ( Parent ( options && options . props ) )
60
69
61
70
// use and plugins from mounting options
62
- if ( options ?. plugins ) {
63
- for ( const use of options . plugins ) vm . use ( use )
71
+ if ( options ?. global ?. plugins ) {
72
+ for ( const use of options ?. global ? .plugins ) vm . use ( use )
64
73
}
65
74
66
75
// use any mixins from mounting options
67
- if ( options ?. mixins ) {
68
- for ( const mixin of options . mixins ) vm . mixin ( mixin )
76
+ if ( options ?. global ?. mixins ) {
77
+ for ( const mixin of options ?. global ? .mixins ) vm . mixin ( mixin )
69
78
}
70
79
71
80
// provide any values passed via provides mounting option
Original file line number Diff line number Diff line change @@ -11,13 +11,17 @@ describe('mounting options: mixins', () => {
11
11
}
12
12
}
13
13
const Component = {
14
- render ( ) { return h ( 'div' ) }
14
+ render ( ) {
15
+ return h ( 'div' )
16
+ }
15
17
}
16
18
17
19
mount ( Component , {
18
- mixins : [ mixin ]
20
+ global : {
21
+ mixins : [ mixin ]
22
+ }
19
23
} )
20
24
21
25
expect ( createdHook ) . toHaveBeenCalled ( )
22
26
} )
23
- } )
27
+ } )
Original file line number Diff line number Diff line change @@ -5,18 +5,24 @@ import { mount } from '../../src'
5
5
describe ( 'mounting options: plugins' , ( ) => {
6
6
it ( 'installs a plugin via `plugins`' , ( ) => {
7
7
const installed = jest . fn ( )
8
+
8
9
class Plugin {
9
10
static install ( ) {
10
11
installed ( )
11
12
}
12
13
}
14
+
13
15
const Component = {
14
- render ( ) { return h ( 'div' ) }
16
+ render ( ) {
17
+ return h ( 'div' )
18
+ }
15
19
}
16
20
mount ( Component , {
17
- plugins : [ Plugin ]
21
+ global : {
22
+ plugins : [ Plugin ]
23
+ }
18
24
} )
19
25
20
26
expect ( installed ) . toHaveBeenCalled ( )
21
27
} )
22
- } )
28
+ } )
You can’t perform that action at this time.
0 commit comments