Added new tests & missing return type to tpl

- Ensuring that various strings from en.json will work
- Added missing return type
This commit is contained in:
Hannah Wolfe 2021-06-09 12:25:45 +01:00
parent b06e2a4577
commit 224c6996f1
2 changed files with 14 additions and 2 deletions

View File

@ -11,7 +11,7 @@ const interpolate = /(?<!{){([^{]+?)}/g;
*
* @param {String} string - string with optional {data properties}
* @param {Object} [data] - optional data to interpolate
* @returns
* @returns {string} the interpolated string
*/
module.exports = (string, data) => {
if (!data) {

View File

@ -20,7 +20,7 @@ describe('tpl', function () {
result.should.eql('Go visit https://example.com');
});
it('Can handle mixing with handlebars-related messages', function () {
it('Can mix interpolation handlebars in the same message', function () {
const string = '{{#get}} helper took {totalMs}ms to complete';
const data = {
totalMs: '500'
@ -30,6 +30,18 @@ describe('tpl', function () {
result.should.eql('{{#get}} helper took 500ms to complete');
});
it('Can mix interpolation with handlebars-block helpers without escaping', function () {
const string = '{{#{helperName}}} helper took {totalMs}ms to complete';
const data = {
helperName: 'get',
totalMs: '500'
};
let result = tpl(string, data);
result.should.eql('{{#get}} helper took 500ms to complete');
});
it('Can handle escaped left braces', function () {
const string = 'The \\{\\{{helperName}}} helper is not available.';
const data = {