@@ -9,9 +9,14 @@ var rimraf = require('rimraf')
99var hash = require ( 'hash-sum' )
1010var SourceMapConsumer = require ( 'source-map' ) . SourceMapConsumer
1111var ExtractTextPlugin = require ( "extract-text-webpack-plugin" )
12+ var compiler = require ( 'vue-template-compiler' )
1213
13- describe ( 'vue-loader' , function ( ) {
14+ function assertRenderFn ( options , template ) {
15+ var compiled = compiler . compile ( template )
16+ expect ( options . render . toString ( ) ) . to . equal ( 'function (){' + compiled . render + '}' )
17+ }
1418
19+ describe ( 'vue-loader' , function ( ) {
1520 var testHTML = '<!DOCTYPE html><html><head></head><body></body></html>'
1621 var outputDir = path . resolve ( __dirname , './output' )
1722 var loaderPath = 'expose?vueModule!' + path . resolve ( __dirname , '../' )
@@ -71,7 +76,7 @@ describe('vue-loader', function () {
7176 entry : './test/fixtures/basic.vue'
7277 } , function ( window ) {
7378 var module = window . vueModule
74- // expect (module.template).to.contain( '<h2 class="red">{{msg}}</h2>')
79+ assertRenderFn ( module , '<h2 class="red">{{msg}}</h2>' )
7580 expect ( module . data ( ) . msg ) . to . contain ( 'Hello from Component A!' )
7681 var style = window . document . querySelector ( 'style' ) . textContent
7782 expect ( style ) . to . contain ( 'comp-a h2 {\n color: #f00;\n}' )
@@ -84,11 +89,13 @@ describe('vue-loader', function () {
8489 entry : './test/fixtures/pre.vue'
8590 } , function ( window ) {
8691 var module = window . vueModule
87- // expect(module.template).to.contain(
88- // '<h1>This is the app</h1>' +
89- // '<comp-a></comp-a>' +
90- // '<comp-b></comp-b>'
91- // )
92+ assertRenderFn ( module ,
93+ '<div>' +
94+ '<h1>This is the app</h1>' +
95+ '<comp-a></comp-a>' +
96+ '<comp-b></comp-b>' +
97+ '</div>'
98+ )
9299 expect ( module . data ( ) . msg ) . to . contain ( 'Hello from coffee!' )
93100 var style = window . document . querySelector ( 'style' ) . textContent
94101 expect ( style ) . to . contain ( 'body {\n font: 100% Helvetica, sans-serif;\n color: #999;\n}' )
@@ -102,12 +109,15 @@ describe('vue-loader', function () {
102109 } , function ( window ) {
103110 var module = window . vueModule
104111 var id = '_v-' + hash ( require . resolve ( './fixtures/scoped-css.vue' ) )
105- // expect(module.template).to.contain(
106- // '<div ' + id + '=""><h1 ' + id + '="">hi</h1></div>\n' +
107- // '<p class="abc def" ' + id + '="">hi</p>\n' +
108- // '<template v-if="ok"><p class="test" ' + id + '="">yo</p></template>\n' +
109- // '<svg ' + id + '=""><template><p ' + id + '=""></p></template></svg>'
110- // )
112+ expect ( module . _scopeId ) . to . equal ( id )
113+ assertRenderFn ( module ,
114+ '<div>' +
115+ '<div><h1>hi</h1></div>\n' +
116+ '<p class="abc def">hi</p>\n' +
117+ '<template v-if="ok"><p class="test">yo</p></template>\n' +
118+ '<svg><template><p></p></template></svg>' +
119+ '</div>'
120+ )
111121 var style = window . document . querySelector ( 'style' ) . textContent
112122 expect ( style ) . to . contain ( '.test[' + id + '] {\n color: yellow;\n}' )
113123 expect ( style ) . to . contain ( '.test[' + id + ']:after {\n content: \'bye!\';\n}' )
@@ -134,7 +144,7 @@ describe('vue-loader', function () {
134144 entry : './test/fixtures/template-import.vue'
135145 } , function ( window ) {
136146 var module = window . vueModule
137- // expect (module.template).to.contain( '<div><h1>hello</h1></div>')
147+ assertRenderFn ( module , '<div><h1>hello</h1></div>' )
138148 done ( )
139149 } )
140150 } )
@@ -232,7 +242,7 @@ describe('vue-loader', function () {
232242 msg : 'Hello from mocked service!'
233243 }
234244 } )
235- // expect (module.template).to.contain( '<div class="msg">{{ msg }}</div>')
245+ assertRenderFn ( module , '<div class="msg">{{ msg }}</div>' )
236246 expect ( module . data ( ) . msg ) . to . contain ( 'Hello from mocked service!' )
237247 done ( )
238248 } )
@@ -254,7 +264,7 @@ describe('vue-loader', function () {
254264 }
255265 } , function ( window ) {
256266 var module = window . vueModule
257- // expect (module.template).to.contain( '<img src="logo.c9e00e.png">\n<img src="logo.c9e00e.png">')
267+ assertRenderFn ( module , '<img src="logo.c9e00e.png">\n<img src="logo.c9e00e.png">' )
258268 var style = window . document . querySelector ( 'style' ) . textContent
259269 expect ( style ) . to . contain ( 'html { background-image: url(logo.c9e00e.png); }' )
260270 expect ( style ) . to . contain ( 'body { background-image: url(logo.c9e00e.png); }' )
0 commit comments