File tree 3 files changed +43
-6
lines changed
3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -66,10 +66,15 @@ ViewModel.use = function (plugin) {
66
66
return utils . warn ( 'Cannot find plugin: ' + plugin )
67
67
}
68
68
}
69
- if ( typeof plugin === 'function' ) {
70
- plugin ( ViewModel )
71
- } else if ( plugin . install ) {
72
- plugin . install ( ViewModel )
69
+
70
+ // additional parameters
71
+ var args = [ ] . slice . call ( arguments , 1 )
72
+ args . unshift ( ViewModel )
73
+
74
+ if ( typeof plugin . install === 'function' ) {
75
+ plugin . install . apply ( plugin , args )
76
+ } else {
77
+ plugin . apply ( null , args )
73
78
}
74
79
}
75
80
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ describe('UNIT: API', function () {
61
61
assert . ok ( called )
62
62
} )
63
63
64
- it ( 'should install a plugin if its a function itself' , function ( ) {
64
+ it ( 'should install a plugin if it’s a function itself' , function ( ) {
65
65
var called = false
66
66
Vue . use ( function ( vue ) {
67
67
called = true
@@ -70,6 +70,36 @@ describe('UNIT: API', function () {
70
70
assert . ok ( called )
71
71
} )
72
72
73
+ it ( 'should pass any additional parameter' , function ( ) {
74
+ var param1 = 'a' ,
75
+ param2 = { b : 'c' }
76
+
77
+ Vue . use ( function ( vue , p1 , p2 ) {
78
+ assert . strictEqual ( p1 , param1 )
79
+ assert . strictEqual ( p2 , param2 )
80
+ } , param1 , param2 )
81
+
82
+ Vue . use ( {
83
+ install : function ( vue , p1 , p2 ) {
84
+ assert . strictEqual ( p1 , param1 )
85
+ assert . strictEqual ( p2 , param2 )
86
+ }
87
+ } , param1 , param2 )
88
+ } )
89
+
90
+ it ( 'should properly set the value of this' , function ( ) {
91
+ var plugin = {
92
+ install : function ( ) {
93
+ assert . strictEqual ( this , plugin )
94
+ }
95
+ }
96
+ Vue . use ( plugin )
97
+
98
+ Vue . use ( function ( ) {
99
+ assert . strictEqual ( this , global )
100
+ } )
101
+ } )
102
+
73
103
} )
74
104
75
105
describe ( 'filter()' , function ( ) {
Original file line number Diff line number Diff line change @@ -42,4 +42,6 @@ Vue.config({silent:true})
42
42
var testDiv = document . createElement ( 'div' )
43
43
testDiv . id = 'test'
44
44
testDiv . style . display = 'none'
45
- document . body . appendChild ( testDiv )
45
+ document . body . appendChild ( testDiv )
46
+
47
+ var global = this
You can’t perform that action at this time.
0 commit comments