Skip to content

Commit

Permalink
fix: STRF-12234 Make moment.js to warn instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
jairo-bc committed Sep 25, 2024
1 parent 61d3deb commit 42d32f0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion helpers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const factory = () => {
return moment(chrono.parseDate(str)).format(pattern);
}


// If handlebars, expose moment methods as hash properties
if (options && options.hash) {
if (options.context) {
Expand All @@ -55,7 +56,7 @@ const factory = () => {
if (Object.keys(moment.prototype).indexOf(key) !== -1 && typeof res[key] === 'function') {
return res[key](options.hash[key]);
} else {
console.error('moment.js does not support "' + key + '"');
console.warn('moment.js does not support "' + key + '"');
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions spec/helpers/moment.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const Sinon = require('sinon');
const Lab = require('lab'),
lab = exports.lab = Lab.script(),
describe = lab.experiment,
it = lab.it,
beforeEach = lab.beforeEach,
afterEach = lab.afterEach,
testRunner = require('../spec-helpers').testRunner;
const Code = require('code'),
expect = Code.expect;
const moment = require('moment');

describe('moment helper', function () {
Expand Down Expand Up @@ -67,4 +72,31 @@ describe('moment helper', function () {
}
], done);
});

describe('when amount is provided', () => {
let consoleWarnCopy = console.warn;

beforeEach(done => {
console.warn = Sinon.fake();
done();
});

afterEach(done => {
console.warn = consoleWarnCopy;
done();
});

it('runs console.warn', (done) => {
runTestCases([
{
input: `{{moment "2022-01-01" isAfter="1999-12-31" amount=1}}`,
output: `true`,
}
], () => {
expect(console.warn.called).to.equal(true);
done();
});

});
});
});

0 comments on commit 42d32f0

Please sign in to comment.