@@ -84,29 +84,30 @@ function test (options, assert) {
84
84
}
85
85
86
86
function 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
+ }
87
98
return options . render . call ( Object . assign ( {
88
99
_v ( val ) {
89
100
return val
90
101
} ,
91
102
_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 ,
103
104
_m ( index ) {
104
105
return options . staticRenderFns [ index ] . call ( this )
105
106
} ,
106
107
_s ( str ) {
107
108
return String ( str )
108
109
}
109
- } , data ) )
110
+ } , data ) , h )
110
111
}
111
112
112
113
function interopDefault ( module ) {
@@ -611,24 +612,28 @@ describe('vue-loader', function () {
611
612
}
612
613
} , code => {
613
614
const renderer = SSR . createBundleRenderer ( code , {
614
- basedir : __dirname
615
+ basedir : __dirname ,
616
+ runInNewContext : 'once'
615
617
} )
616
618
const context = {
617
619
_registeredComponents : new Set ( )
618
620
}
619
621
renderer . renderToString ( context , ( err , res ) => {
620
622
if ( err ) return done ( err )
621
- expect ( res ) . to . contain ( 'server-rendered' )
623
+ expect ( res ) . to . contain ( 'data- server-rendered' )
622
624
expect ( res ) . to . contain ( '<h1>Hello</h1>' )
623
625
expect ( res ) . to . contain ( 'Hello from Component A!' )
626
+ expect ( res ) . to . contain ( '<div class="foo">functional</div>' )
624
627
// from main component
625
628
expect ( context . styles ) . to . contain ( 'h1 { color: green;' )
626
629
// from imported child component
627
630
expect ( context . styles ) . to . contain ( 'comp-a h2 {\n color: #f00;' )
628
631
// from imported css file
629
632
expect ( context . styles ) . to . contain ( 'h1 { color: red;' )
633
+ // from imported functional component
634
+ expect ( context . styles ) . to . contain ( '.foo { color: red;' )
630
635
// 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 )
632
637
done ( )
633
638
} )
634
639
} )
@@ -834,4 +839,22 @@ describe('vue-loader', function () {
834
839
done ( )
835
840
} )
836
841
} )
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
+ } )
837
860
} )
0 commit comments