11describe ( 'Utils' , function ( ) {
2+ afterEach ( cleanupMocks )
23
34 var utils = require ( 'vue/src/utils' ) ,
45 config = require ( 'vue/src/config' )
@@ -215,28 +216,14 @@ describe('Utils', function () {
215216
216217 describe ( 'toFragment' , function ( ) {
217218
218- it ( 'should convert a string tempalte to a documentFragment' , function ( ) {
219+ it ( 'should convert a string template to a documentFragment' , function ( ) {
219220 var template = '<div class="a">hi</div><p>ha</p>' ,
220221 frag = utils . toFragment ( template )
221222 assert . ok ( frag instanceof window . DocumentFragment )
222223 assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
223224 assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
224225 } )
225226
226- it ( 'should also work if the string is an ID selector' , function ( ) {
227- var id = 'utils-template-to-fragment' ,
228- template = '<div class="a">hi</div><p>ha</p>' ,
229- el = document . createElement ( 'template' )
230- el . id = id
231- el . innerHTML = template
232- document . getElementById ( 'test' ) . appendChild ( el )
233-
234- var frag = utils . toFragment ( '#' + id )
235- assert . ok ( frag instanceof window . DocumentFragment )
236- assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
237- assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
238- } )
239-
240227 it ( 'should work with table elements' , function ( ) {
241228 var frag = utils . toFragment ( '<td></td>' )
242229 assert . ok ( frag instanceof window . DocumentFragment )
@@ -252,6 +239,75 @@ describe('Utils', function () {
252239
253240 } )
254241
242+ describe ( 'parseTemplateOption' , function ( ) {
243+
244+ afterEach ( cleanupMocks )
245+
246+ it ( 'should convert a string template to a documentFragment' , function ( ) {
247+ var template = '<div class="a">hi</div><p>ha</p>' ,
248+ frag = utils . parseTemplateOption ( template )
249+ assert . ok ( frag instanceof window . DocumentFragment )
250+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
251+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
252+ } )
253+
254+ describe ( 'id selector' , function ( ) {
255+ it ( 'should work with a TEMPLATE tag' , function ( ) {
256+ var id = 'utils-template-parse-template-option-template-tag' ,
257+ template = '<div class="a">hi</div><p>ha</p>' ,
258+ el = document . createElement ( 'template' )
259+ el . id = id
260+ el . innerHTML = template
261+ appendMock ( el )
262+
263+ var frag = utils . parseTemplateOption ( '#' + id )
264+ assert . ok ( frag instanceof window . DocumentFragment )
265+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
266+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
267+ } )
268+
269+ it ( 'should work with a DIV tag' , function ( ) {
270+ var id = 'utils-template-parse-template-option-div-tag' ,
271+ template = '<div class="a">hi</div><p>ha</p>' ,
272+ el = document . createElement ( 'div' )
273+ el . id = id
274+ el . innerHTML = template
275+ appendMock ( el )
276+
277+ var frag = utils . parseTemplateOption ( '#' + id )
278+ assert . ok ( frag instanceof window . DocumentFragment )
279+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
280+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
281+ } )
282+ } )
283+
284+ describe ( 'when passed a Node' , function ( ) {
285+ it ( 'should work with a TEMPLATE tag' , function ( ) {
286+ var el = document . createElement ( 'template' )
287+ el . innerHTML = '<div class="a">hi</div><p>ha</p>'
288+
289+ var frag = utils . parseTemplateOption ( el )
290+ assert . ok ( frag instanceof window . DocumentFragment )
291+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
292+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
293+ } )
294+
295+ it ( 'should work with a DIV tag' , function ( ) {
296+ var el = document . createElement ( 'div' )
297+ el . innerHTML = '<span class="a">hi</span><p>ha</p>'
298+
299+ var frag = utils . parseTemplateOption ( el )
300+ assert . ok ( frag instanceof window . DocumentFragment )
301+
302+ assert . equal ( frag . firstChild . outerHTML , el . outerHTML )
303+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
304+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
305+ } )
306+ } )
307+
308+
309+ } )
310+
255311 describe ( 'toConstructor' , function ( ) {
256312
257313 it ( 'should convert an non-VM object to a VM constructor' , function ( ) {
@@ -270,6 +326,17 @@ describe('Utils', function () {
270326
271327 describe ( 'processOptions' , function ( ) {
272328
329+ beforeEach ( function ( ) {
330+ var id = 'utils-template-to-fragment' ,
331+ template = '<div class="a">hi</div><p>ha</p>' ,
332+ el = document . createElement ( 'template' )
333+ el . id = id
334+ el . innerHTML = template
335+ appendMock ( el )
336+ } )
337+
338+ afterEach ( cleanupMocks )
339+
273340 var options = {
274341 partials : {
275342 a : '#utils-template-to-fragment' ,
0 commit comments