From c4e56efa16590f719ad411eb06449cd7f3f4863b Mon Sep 17 00:00:00 2001 From: Enno Woortmann Date: Mon, 26 Aug 2019 21:25:04 +0200 Subject: [PATCH] Add test cases for custom functions in partials (#713) These tests cases proves the partial indention changes that got released in mustache v3.0.2 broke function output in partials with indentation. --- test/partial-test.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/test/partial-test.js b/test/partial-test.js index b76fb5850..bbc37bbb6 100644 --- a/test/partial-test.js +++ b/test/partial-test.js @@ -109,4 +109,34 @@ describe('Partials spec', function () { var renderResult = Mustache.render(template, data, partials); assert.equal(renderResult, expected); }); -}); \ No newline at end of file + + it('Partial without indentation should inherit functions.', function () { + var template = '{{> partial }}'; + var data = { + toUpperCase: function () { + return function (label) { + return label.toUpperCase(); + }; + } + }; + var partials = {partial: 'aA-{{ #toUpperCase }}Input{{ /toUpperCase }}-Aa'}; + var expected = 'aA-INPUT-Aa'; + var renderResult = Mustache.render(template, data, partials); + assert.equal(renderResult, expected); + }); + + it('Partial with indentation should inherit functions.', function () { + var template = ' {{> partial }}'; + var data = { + toUpperCase: function () { + return function (label) { + return label.toUpperCase(); + }; + } + }; + var partials = {partial: 'aA-{{ #toUpperCase }}Input{{ /toUpperCase }}-Aa'}; + var expected = ' aA-INPUT-Aa'; + var renderResult = Mustache.render(template, data, partials); + assert.equal(renderResult, expected); + }); +});