1+ /* global cleanupMocks, appendMock */
2+
13describe ( 'Utils' , function ( ) {
4+ afterEach ( cleanupMocks )
25
36 var utils = require ( 'vue/src/utils' ) ,
47 config = require ( 'vue/src/config' )
@@ -215,28 +218,14 @@ describe('Utils', function () {
215218
216219 describe ( 'toFragment' , function ( ) {
217220
218- it ( 'should convert a string tempalte to a documentFragment' , function ( ) {
221+ it ( 'should convert a string template to a documentFragment' , function ( ) {
219222 var template = '<div class="a">hi</div><p>ha</p>' ,
220223 frag = utils . toFragment ( template )
221224 assert . ok ( frag instanceof window . DocumentFragment )
222225 assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
223226 assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
224227 } )
225228
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-
240229 it ( 'should work with table elements' , function ( ) {
241230 var frag = utils . toFragment ( '<td></td>' )
242231 assert . ok ( frag instanceof window . DocumentFragment )
@@ -252,6 +241,75 @@ describe('Utils', function () {
252241
253242 } )
254243
244+ describe ( 'parseTemplateOption' , function ( ) {
245+
246+ afterEach ( cleanupMocks )
247+
248+ it ( 'should convert a string template to a documentFragment' , function ( ) {
249+ var template = '<div class="a">hi</div><p>ha</p>' ,
250+ frag = utils . parseTemplateOption ( template )
251+ assert . ok ( frag instanceof window . DocumentFragment )
252+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
253+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
254+ } )
255+
256+ describe ( 'id selector' , function ( ) {
257+ it ( 'should work with a TEMPLATE tag' , function ( ) {
258+ var id = 'utils-template-parse-template-option-template-tag' ,
259+ template = '<div class="a">hi</div><p>ha</p>' ,
260+ el = document . createElement ( 'template' )
261+ el . id = id
262+ el . innerHTML = template
263+ appendMock ( el )
264+
265+ var frag = utils . parseTemplateOption ( '#' + id )
266+ assert . ok ( frag instanceof window . DocumentFragment )
267+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
268+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
269+ } )
270+
271+ it ( 'should work with a DIV tag' , function ( ) {
272+ var id = 'utils-template-parse-template-option-div-tag' ,
273+ template = '<div class="a">hi</div><p>ha</p>' ,
274+ el = document . createElement ( 'div' )
275+ el . id = id
276+ el . innerHTML = template
277+ appendMock ( el )
278+
279+ var frag = utils . parseTemplateOption ( '#' + id )
280+ assert . ok ( frag instanceof window . DocumentFragment )
281+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
282+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
283+ } )
284+ } )
285+
286+ describe ( 'when passed a Node' , function ( ) {
287+ it ( 'should work with a TEMPLATE tag' , function ( ) {
288+ var el = document . createElement ( 'template' )
289+ el . innerHTML = '<div class="a">hi</div><p>ha</p>'
290+
291+ var frag = utils . parseTemplateOption ( el )
292+ assert . ok ( frag instanceof window . DocumentFragment )
293+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
294+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
295+ } )
296+
297+ it ( 'should work with a DIV tag' , function ( ) {
298+ var el = document . createElement ( 'div' )
299+ el . innerHTML = '<span class="a">hi</span><p>ha</p>'
300+
301+ var frag = utils . parseTemplateOption ( el )
302+ assert . ok ( frag instanceof window . DocumentFragment )
303+
304+ assert . equal ( frag . firstChild . outerHTML , el . outerHTML )
305+ assert . equal ( frag . querySelector ( '.a' ) . textContent , 'hi' )
306+ assert . equal ( frag . querySelector ( 'p' ) . textContent , 'ha' )
307+ } )
308+ } )
309+
310+
311+ } )
312+
255313 describe ( 'toConstructor' , function ( ) {
256314
257315 it ( 'should convert an non-VM object to a VM constructor' , function ( ) {
@@ -270,6 +328,17 @@ describe('Utils', function () {
270328
271329 describe ( 'processOptions' , function ( ) {
272330
331+ beforeEach ( function ( ) {
332+ var id = 'utils-template-to-fragment' ,
333+ template = '<div class="a">hi</div><p>ha</p>' ,
334+ el = document . createElement ( 'template' )
335+ el . id = id
336+ el . innerHTML = template
337+ appendMock ( el )
338+ } )
339+
340+ afterEach ( cleanupMocks )
341+
273342 var options = {
274343 partials : {
275344 a : '#utils-template-to-fragment' ,
0 commit comments