1
0
mirror of /repos/Prototyper.git synced 2025-12-30 06:31:32 +01:00

first test

This commit is contained in:
Aiko Mastboom 2013-05-12 11:54:55 +02:00
parent e1c0b27948
commit 82f47bb27c
3 changed files with 31 additions and 2 deletions

View File

@ -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]];

View File

@ -252,7 +252,7 @@ module.exports = function (config, mongoDataInstance, helpers, markers) {
return {
getPreviewHTML: getPreviewHTML,
_replaceMarkers: replaceMarkers
_replaceMarkers: replaceMarkers
};
};

29
test/test.helpers.js Normal file
View File

@ -0,0 +1,29 @@
var helpers = require('../helpers.js');
var expect = require('chai').expect;
var when = require('when');
describe('Helpers', function () {
var marker_prefix = '<!--\\s*@@';
var marker_postfix = '\\s*-->';
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);
}
);
})
});
});