@@ -2,6 +2,7 @@ import ComponentWithChild from '~resources/components/component-with-child.vue'
22import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue'
33import Component from '~resources/components/component.vue'
44import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
5+ import ComponentWithNestedChildrenAndAttributes from '~resources/components/component-with-nested-childern-and-attributes.vue'
56import { createLocalVue , config } from '@vue/test-utils'
67import { config as serverConfig } from '@vue/server-test-utils'
78import Vue from 'vue'
@@ -18,6 +19,7 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
1819 serverConfigSave = serverConfig . stubs
1920 config . stubs = { }
2021 serverConfig . stubs = { }
22+ sandbox . stub ( console , 'error' ) . callThrough ( )
2123 } )
2224
2325 afterEach ( ( ) => {
@@ -32,21 +34,24 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
3234 const ComponentWithoutRender = { template : '<div></div>' }
3335 const ExtendedComponent = { extends : ComponentWithRender }
3436 const SubclassedComponent = Vue . extend ( { template : '<div></div>' } )
37+ const StringComponent = '<div></div>'
3538 mountingMethod ( ComponentWithChild , {
3639 stubs : {
3740 ChildComponent : ComponentWithRender ,
3841 ChildComponent2 : ComponentAsAClass ,
3942 ChildComponent3 : ComponentWithoutRender ,
4043 ChildComponent4 : ExtendedComponent ,
41- ChildComponent5 : SubclassedComponent
44+ ChildComponent5 : SubclassedComponent ,
45+ ChildComponent6 : StringComponent
4246 }
4347 } )
4448 } )
4549
4650 it ( 'replaces component with template string ' , ( ) => {
51+ const Stub = { template : '<div class="stub"></div>' }
4752 const wrapper = mountingMethod ( ComponentWithChild , {
4853 stubs : {
49- ChildComponent : '<div class="stub"></div>'
54+ ChildComponent : Stub
5055 }
5156 } )
5257 expect ( wrapper . findAll ( '.stub' ) . length ) . to . equal ( 1 )
@@ -321,7 +326,7 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
321326
322327 const wrapper = mountingMethod ( TestComponent , {
323328 stubs : {
324- 'span-component' : '<p />'
329+ 'span-component' : { template : '<p />' }
325330 } ,
326331 localVue
327332 } )
@@ -342,7 +347,7 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
342347
343348 const wrapper = mountingMethod ( TestComponent , {
344349 stubs : {
345- 'time-component' : '<span />'
350+ 'time-component' : { template : '<span />' }
346351 } ,
347352 localVue
348353 } )
@@ -414,7 +419,7 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
414419 expect ( wrapper . html ( ) ) . contains ( 'No render function' )
415420 } )
416421
417- it ( 'throws an error when passed a circular reference' , ( ) => {
422+ it ( 'throws an error when passed a circular reference for string stubs ' , ( ) => {
418423 const names = [ 'child-component' , 'ChildComponent' , 'childComponent' ]
419424 const validValues = [
420425 '<NAME-suffix />' ,
@@ -590,4 +595,52 @@ describeWithShallowAndMount('options.stub', mountingMethod => {
590595 expect ( result . props ( ) . propA ) . to . equal ( 'A' )
591596 delete Vue . options . components [ 'child-component' ]
592597 } )
598+
599+ itRunIf (
600+ vueVersion >= 2.2 ,
601+ 'renders props in the element as attributes' ,
602+ ( ) => {
603+ const ComponentStub = { template : '<div id="component-stub" />' }
604+ const StringStub = '<div id="string-stub" />'
605+ const BooleanStub = true
606+
607+ const wrapper = mountingMethod ( ComponentWithNestedChildrenAndAttributes , {
608+ stubs : {
609+ SlotComponent : ComponentStub ,
610+ ChildComponent : StringStub ,
611+ OriginalComponent : BooleanStub
612+ }
613+ } )
614+
615+ expect ( wrapper . find ( '#component-stub' ) . attributes ( ) ) . to . eql ( {
616+ id : 'component-stub' ,
617+ prop1 : 'foobar' ,
618+ prop2 : 'fizzbuzz'
619+ } )
620+ expect ( wrapper . find ( '#string-stub' ) . attributes ( ) ) . to . eql ( {
621+ id : 'string-stub' ,
622+ prop1 : 'foobar' ,
623+ prop2 : 'fizzbuzz'
624+ } )
625+ expect ( wrapper . find ( 'originalcomponent-stub' ) . attributes ( ) ) . to . eql ( {
626+ prop1 : 'foobar' ,
627+ prop2 : 'fizzbuzz'
628+ } )
629+ }
630+ )
631+
632+ it ( 'warns when passing a string' , ( ) => {
633+ const StringComponent = '<div></div>'
634+ mountingMethod ( ComponentWithChild , {
635+ stubs : {
636+ ChildComponent6 : StringComponent
637+ }
638+ } )
639+
640+ expect ( console . error ) . calledWith (
641+ sandbox . match (
642+ '[vue-test-utils]: String stubs are deprecated and will be removed in future versions'
643+ )
644+ )
645+ } )
593646} )
0 commit comments