@@ -298,4 +298,105 @@ describe('Options provide/inject', () => {
298298 expect ( `Injection "bar" not found` ) . not . toHaveBeenWarned ( )
299299 expect ( `Injection "baz" not found` ) . not . toHaveBeenWarned ( )
300300 } )
301+
302+ // Github issue #6008
303+ it ( 'should merge provide from mixins (objects)' , ( ) => {
304+ const mixinA = { provide : { foo : 'foo' } }
305+ const mixinB = { provide : { bar : 'bar' } }
306+ const child = {
307+ inject : [ 'foo' , 'bar' ] ,
308+ template : `<span/>` ,
309+ created ( ) {
310+ injected = [ this . foo , this . bar ]
311+ }
312+ }
313+ new Vue ( {
314+ mixins : [ mixinA , mixinB ] ,
315+ render ( h ) {
316+ return h ( child )
317+ }
318+ } ) . $mount ( )
319+
320+ expect ( injected ) . toEqual ( [ 'foo' , 'bar' ] )
321+ } )
322+ it ( 'should merge provide from mixins (functions)' , ( ) => {
323+ const mixinA = { provide : ( ) => ( { foo : 'foo' } ) }
324+ const mixinB = { provide : ( ) => ( { bar : 'bar' } ) }
325+ const child = {
326+ inject : [ 'foo' , 'bar' ] ,
327+ template : `<span/>` ,
328+ created ( ) {
329+ injected = [ this . foo , this . bar ]
330+ }
331+ }
332+ new Vue ( {
333+ mixins : [ mixinA , mixinB ] ,
334+ render ( h ) {
335+ return h ( child )
336+ }
337+ } ) . $mount ( )
338+
339+ expect ( injected ) . toEqual ( [ 'foo' , 'bar' ] )
340+ } )
341+ it ( 'should merge provide from mixins (mix of objects and functions)' , ( ) => {
342+ const mixinA = { provide : { foo : 'foo' } }
343+ const mixinB = { provide : ( ) => ( { bar : 'bar' } ) }
344+ const mixinC = { provide : { baz : 'baz' } }
345+ const mixinD = { provide : ( ) => ( { bam : 'bam' } ) }
346+ const child = {
347+ inject : [ 'foo' , 'bar' , 'baz' , 'bam' ] ,
348+ template : `<span/>` ,
349+ created ( ) {
350+ injected = [ this . foo , this . bar , this . baz , this . bam ]
351+ }
352+ }
353+ new Vue ( {
354+ mixins : [ mixinA , mixinB , mixinC , mixinD ] ,
355+ render ( h ) {
356+ return h ( child )
357+ }
358+ } ) . $mount ( )
359+
360+ expect ( injected ) . toEqual ( [ 'foo' , 'bar' , 'baz' , 'bam' ] )
361+ } )
362+ it ( 'should merge provide from mixins and override existing keys' , ( ) => {
363+ const mixinA = { provide : { foo : 'foo' } }
364+ const mixinB = { provide : { foo : 'bar' } }
365+ const child = {
366+ inject : [ 'foo' ] ,
367+ template : `<span/>` ,
368+ created ( ) {
369+ injected = [ this . foo ]
370+ }
371+ }
372+ new Vue ( {
373+ mixins : [ mixinA , mixinB ] ,
374+ render ( h ) {
375+ return h ( child )
376+ }
377+ } ) . $mount ( )
378+
379+ expect ( injected ) . toEqual ( [ 'bar' ] )
380+ } )
381+ it ( 'should merge provide when Vue.extend' , ( ) => {
382+ const mixinA = { provide : ( ) => ( { foo : 'foo' } ) }
383+ const child = {
384+ inject : [ 'foo' , 'bar' ] ,
385+ template : `<span/>` ,
386+ created ( ) {
387+ injected = [ this . foo , this . bar ]
388+ }
389+ }
390+ const Ctor = Vue . extend ( {
391+ mixins : [ mixinA ] ,
392+ provide : { bar : 'bar' } ,
393+ render ( h ) {
394+ return h ( child )
395+ }
396+ } )
397+
398+ new Ctor ( ) . $mount ( )
399+
400+ expect ( injected ) . toEqual ( [ 'foo' , 'bar' ] )
401+ } )
301402} )
0 commit comments