From d170f41c852e838fdf56657c43c353b94eb3243f Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Sun, 11 Nov 2018 21:43:52 +0100 Subject: [PATCH] Add test to verify custom tags are used in partials for via `.render()` --- test/render-test.js | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/test/render-test.js b/test/render-test.js index dbcfc4c..1041dd4 100644 --- a/test/render-test.js +++ b/test/render-test.js @@ -17,37 +17,47 @@ describe('Mustache.render', function () { 'for mustache#render(template, view, partials)'); }); - it('uses tags argument instead of Mustache.tags when given', function () { - var template = '<>bar{{placeholder}}'; + describe('custom tags', function () { + it('uses tags argument instead of Mustache.tags when given', function () { + var template = '<>bar{{placeholder}}'; - Mustache.tags = ['{{', '}}']; - assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']), 'foobar{{placeholder}}'); - }); + Mustache.tags = ['{{', '}}']; + assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']), 'foobar{{placeholder}}'); + }); - it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using Mustache.tags', function () { - var template = '((placeholder))bar{{placeholder}}'; + it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using Mustache.tags', function () { + var template = '((placeholder))bar{{placeholder}}'; - Mustache.tags = ['{{', '}}']; - Mustache.render(template, { placeholder: 'foo' }); - assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['((', '))']), 'foobar{{placeholder}}'); - }); + Mustache.tags = ['{{', '}}']; + Mustache.render(template, { placeholder: 'foo' }); + assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['((', '))']), 'foobar{{placeholder}}'); + }); - it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using different tags', function () { - var template = '[[placeholder]]bar<>'; + it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using different tags', function () { + var template = '[[placeholder]]bar<>'; - Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']); - assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<>'); - }); + Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']); + assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<>'); + }); - it('does not mutate Mustache.tags when given tags argument', function() { - var correctMustacheTags = ['{{', '}}']; - Mustache.tags = correctMustacheTags; + it('does not mutate Mustache.tags when given tags argument', function() { + var correctMustacheTags = ['{{', '}}']; + Mustache.tags = correctMustacheTags; - Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, ['((', '))']); + Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, ['((', '))']); - assert.equal(Mustache.tags, correctMustacheTags); - assert.deepEqual(Mustache.tags, ['{{', '}}']); - }); + assert.equal(Mustache.tags, correctMustacheTags); + assert.deepEqual(Mustache.tags, ['{{', '}}']); + }); + + it('uses provided tags when rendering partials', function () { + var output = Mustache.render('<%> partial %>', { name: 'Santa Claus' }, { + partial: '<% name %>' + }, ['<%', '%>']); + + assert.equal(output, 'Santa Claus'); + }) + }) tests.forEach(function (test) { var view = eval(test.view);