File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
test/unit/features/global-api Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,11 @@ import { toArray } from '../util/index'
4
4
5
5
export function initUse ( Vue : GlobalAPI ) {
6
6
Vue . use = function ( plugin : Function | Object ) {
7
- /* istanbul ignore if */
8
- if ( plugin . installed ) {
7
+ const cid = this . cid
8
+ if ( ! plugin . _installed ) {
9
+ plugin . _installed = { }
10
+ }
11
+ if ( plugin . _installed [ cid ] ) {
9
12
return this
10
13
}
11
14
// additional parameters
@@ -16,7 +19,7 @@ export function initUse (Vue: GlobalAPI) {
16
19
} else if ( typeof plugin === 'function' ) {
17
20
plugin . apply ( null , args )
18
21
}
19
- plugin . installed = true
22
+ plugin . _installed [ cid ] = true
20
23
return this
21
24
}
22
25
}
Original file line number Diff line number Diff line change @@ -14,11 +14,23 @@ describe('Global API: use', () => {
14
14
Vue . use ( pluginStub , options )
15
15
expect ( Vue . options . directives [ 'plugin-test' ] ) . toBe ( def )
16
16
delete Vue . options . directives [ 'plugin-test' ]
17
+ expect ( Vue . options . directives [ 'plugin-test' ] ) . toBeUndefined ( )
18
+
19
+ // should not double apply
20
+ Vue . use ( pluginStub , options )
21
+ expect ( Vue . options . directives [ 'plugin-test' ] ) . toBeUndefined ( )
17
22
} )
18
23
19
24
it ( 'should apply Function plugin' , ( ) => {
20
25
Vue . use ( pluginStub . install , options )
21
26
expect ( Vue . options . directives [ 'plugin-test' ] ) . toBe ( def )
22
27
delete Vue . options . directives [ 'plugin-test' ]
23
28
} )
29
+
30
+ it ( 'should work on extended constructors without polluting the base' , ( ) => {
31
+ const Ctor = Vue . extend ( { } )
32
+ Ctor . use ( pluginStub , options )
33
+ expect ( Vue . options . directives [ 'plugin-test' ] ) . toBeUndefined ( )
34
+ expect ( Ctor . options . directives [ 'plugin-test' ] ) . toBe ( def )
35
+ } )
24
36
} )
You can’t perform that action at this time.
0 commit comments