File tree 2 files changed +23
-6
lines changed
test/unit/specs/mount/options
2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 1
1
function addProvide ( component , options ) {
2
- const provideOption = Object . assign ( { } , options . provide )
2
+ const provide = typeof options . provide === 'function'
3
+ ? options . provide
4
+ : Object . assign ( { } , options . provide )
5
+
3
6
delete options . provide
4
7
5
8
const originalBeforeCreate = component . beforeCreate
6
9
component . beforeCreate = function beforeCreate ( ) {
7
- this . _provided = provideOption
10
+ this . _provided = typeof provide === 'function'
11
+ ? provide . call ( this )
12
+ : provide
8
13
9
14
if ( originalBeforeCreate ) {
10
15
originalBeforeCreate . call ( this )
Original file line number Diff line number Diff line change @@ -2,17 +2,29 @@ import mount from '../../../../../src/mount'
2
2
import ComponentWithInject from '../../../../resources/components/component-with-inject.vue'
3
3
4
4
describe ( 'provide option in mount' , ( ) => {
5
- it ( 'provides value which is injected by mounted component' , ( ) => {
5
+ it ( 'provides objects which is injected by mounted component' , ( ) => {
6
6
const wrapper = mount ( ComponentWithInject , {
7
- provide : { fromMount : 'providedValue ' }
7
+ provide : { fromMount : 'objectValue ' }
8
8
} )
9
9
10
- expect ( wrapper . text ( ) ) . to . contain ( 'providedValue' )
10
+ expect ( wrapper . text ( ) ) . to . contain ( 'objectValue' )
11
+ } )
12
+
13
+ it ( 'provides function which is injected by mounted component' , ( ) => {
14
+ const wrapper = mount ( ComponentWithInject , {
15
+ provide ( ) {
16
+ return {
17
+ fromMount : 'functionValue'
18
+ }
19
+ }
20
+ } )
21
+
22
+ expect ( wrapper . text ( ) ) . to . contain ( 'functionValue' )
11
23
} )
12
24
13
25
it ( 'supports beforeCreate in component' , ( ) => {
14
26
const wrapper = mount ( ComponentWithInject , {
15
- provide : { fromMount : 'providedValue ' }
27
+ provide : { fromMount : '_ ' }
16
28
} )
17
29
18
30
expect ( wrapper . vm . setInBeforeCreate ) . to . equal ( 'created' )
You can’t perform that action at this time.
0 commit comments