diff --git a/helpers.js b/helpers.js index c45d9ee..1715270 100644 --- a/helpers.js +++ b/helpers.js @@ -6,7 +6,7 @@ module.exports = function (markers) { function replace(text, marker, getReplacement, once) { var deferred = when.defer(); var regExp = new RegExp(markers.prefix + marker + markers.postfix, 'gmi'); - var matches = text.match(regExp); + var matches = text && text.match && text.match(regExp); if (matches) { if (once) { matches = [matches[0]]; diff --git a/preview.js b/preview.js index 92ea368..730437f 100644 --- a/preview.js +++ b/preview.js @@ -252,7 +252,7 @@ module.exports = function (config, mongoDataInstance, helpers, markers) { return { getPreviewHTML: getPreviewHTML, - _replaceMarkers: replaceMarkers + _replaceMarkers: replaceMarkers }; }; diff --git a/test/test.helpers.js b/test/test.helpers.js new file mode 100644 index 0000000..7a24dff --- /dev/null +++ b/test/test.helpers.js @@ -0,0 +1,29 @@ +var helpers = require('../helpers.js'); +var expect = require('chai').expect; +var when = require('when'); + + +describe('Helpers', function () { + var marker_prefix = ''; + var helper = helpers({ + prefix: marker_prefix, + postfix: marker_postfix + }); + + describe('replace', function (done) { + it('', function () { + var promise = helper.replace(null, null, null, true); + expect(promise).to.be.an('object'); + when(promise).then( + function onSuccess(result) { + expect(result).to.be.an('object'); + expect(result).to.be.empty(); + done(); + }, function onFailure(err) { + done(err); + } + ); + }) + }); +});