@@ -84,29 +84,30 @@ function test (options, assert) {
8484}
8585
8686function mockRender ( options , data ) {
87+ function h ( tag , data , children ) {
88+ if ( Array . isArray ( data ) ) {
89+ children = data
90+ data = null
91+ }
92+ return {
93+ tag : tag ,
94+ data : data ,
95+ children : children
96+ }
97+ }
8798 return options . render . call ( Object . assign ( {
8899 _v ( val ) {
89100 return val
90101 } ,
91102 _self : { } ,
92- $createElement ( tag , data , children ) {
93- if ( Array . isArray ( data ) ) {
94- children = data
95- data = null
96- }
97- return {
98- tag : tag ,
99- data : data ,
100- children : children
101- }
102- } ,
103+ $createElement : h ,
103104 _m ( index ) {
104105 return options . staticRenderFns [ index ] . call ( this )
105106 } ,
106107 _s ( str ) {
107108 return String ( str )
108109 }
109- } , data ) )
110+ } , data ) , h )
110111}
111112
112113function interopDefault ( module ) {
@@ -611,24 +612,28 @@ describe('vue-loader', function () {
611612 }
612613 } , code => {
613614 const renderer = SSR . createBundleRenderer ( code , {
614- basedir : __dirname
615+ basedir : __dirname ,
616+ runInNewContext : 'once'
615617 } )
616618 const context = {
617619 _registeredComponents : new Set ( )
618620 }
619621 renderer . renderToString ( context , ( err , res ) => {
620622 if ( err ) return done ( err )
621- expect ( res ) . to . contain ( 'server-rendered' )
623+ expect ( res ) . to . contain ( 'data- server-rendered' )
622624 expect ( res ) . to . contain ( '<h1>Hello</h1>' )
623625 expect ( res ) . to . contain ( 'Hello from Component A!' )
626+ expect ( res ) . to . contain ( '<div class="foo">functional</div>' )
624627 // from main component
625628 expect ( context . styles ) . to . contain ( 'h1 { color: green;' )
626629 // from imported child component
627630 expect ( context . styles ) . to . contain ( 'comp-a h2 {\n color: #f00;' )
628631 // from imported css file
629632 expect ( context . styles ) . to . contain ( 'h1 { color: red;' )
633+ // from imported functional component
634+ expect ( context . styles ) . to . contain ( '.foo { color: red;' )
630635 // collect component identifiers during render
631- expect ( Array . from ( context . _registeredComponents ) . length ) . to . equal ( 2 )
636+ expect ( Array . from ( context . _registeredComponents ) . length ) . to . equal ( 3 )
632637 done ( )
633638 } )
634639 } )
@@ -834,4 +839,22 @@ describe('vue-loader', function () {
834839 done ( )
835840 } )
836841 } )
842+
843+ it ( 'functional component with styles' , done => {
844+ test ( {
845+ entry : './test/fixtures/functional-style.vue'
846+ } , ( window , module , rawModule ) => {
847+ expect ( module . functional ) . to . equal ( true )
848+ var vnode = mockRender ( module )
849+ // <div class="foo">hi</div>
850+ expect ( vnode . tag ) . to . equal ( 'div' )
851+ expect ( vnode . data . class ) . to . equal ( 'foo' )
852+ expect ( vnode . children [ 0 ] ) . to . equal ( 'functional' )
853+
854+ var style = window . document . querySelector ( 'style' ) . textContent
855+ style = normalizeNewline ( style )
856+ expect ( style ) . to . contain ( '.foo { color: red;\n}' )
857+ done ( )
858+ } )
859+ } )
837860} )
0 commit comments