Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.idea
package-lock.json
dist
coverage.html
6 changes: 6 additions & 0 deletions spec/helpers/assignVar-getVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ describe('assignVar and getVar helpers', function() {
});
});

it('should throw an exception if the assignVar value is not a string or number', function (done) {
renderString('{{assignVar "key" true}}').catch(_ => {
done();
});
});

it('should assign and get variables', function(done) {
runTestCases([
{
Expand Down
23 changes: 23 additions & 0 deletions spec/helpers/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,27 @@ describe('compare helper', function() {
},
], done);
});

it('should use default operator when none specified', function(done) {
runTestCases([
{
input: '{{#compare num1 1}}big{{/compare}}',
output: 'big',
},
], done);
});

it('should throw error when less than 2 parameters provided', function(done) {
const renderString = require('../spec-helpers').renderString;
renderString('{{#compare num1}}big{{/compare}}', context).catch(_ => {
done();
});
});

it('should throw error when invalid operator is used', function(done) {
const renderString = require('../spec-helpers').renderString;
renderString('{{#compare num1 num2 operator="invalid"}}big{{/compare}}', context).catch(_ => {
done();
});
});
});
7 changes: 7 additions & 0 deletions spec/helpers/decrementVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@ describe('decrementVar helper', function() {
},
], done);
});

it('should throw error when max keys exceeded', function(done) {
const template = `{{#for 1 51}}{{decrementVar (multiConcat 'data' this.$index)}}{{/for}}`;
renderString(template).catch(_ => {
done();
});
});
});
16 changes: 16 additions & 0 deletions spec/helpers/incrementVar.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,20 @@ describe('incrementVar helper', function() {
},
], done);
});

it('should throw error when max keys exceeded', function(done) {
const template = `{{#for 1 51}}{{incrementVar (multiConcat 'data' this.$index)}}{{/for}}`;
renderString(template).catch(_ => {
done();
});
});

it('should return undefined for non-existent key after clearing', function(done) {
runTestCases([
{
input: '{{incrementVar "newkey"}}',
output: '0',
},
], done);
});
});
23 changes: 23 additions & 0 deletions spec/helpers/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,27 @@ describe('inject helper', function() {
},
], done);
});

it('should do nothing when injecting a function', function(done) {
const functionContext = Object.assign({}, context, {
myFunction: function() { return 'test'; }
});
const runTestCasesWithFunction = testRunner({context: functionContext});

runTestCasesWithFunction([
{
input: "{{inject 'func' myFunction}}{{jsContext}}",
output: '"{}"',
},
], done);
});

it('should return empty object when no variables injected', function(done) {
runTestCases([
{
input: "{{jsContext}}",
output: '"{}"',
},
], done);
});
});
39 changes: 39 additions & 0 deletions spec/helpers/nonce.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,43 @@ describe('nonce helper', function () {
},
], done);
});

it('should not render a nonce when no security in params', function (done) {
const requestParams = {}
const renderer = buildRenderer({}, {}, {}, null, requestParams);
const runTestCases = testRunner({context, renderer});
runTestCases([
{
input: '{{nonce}}',
output: '',
},
], done);
});

it('should not render a nonce when params is null', function (done) {
const renderer = buildRenderer({}, {}, {}, null, null);
const runTestCases = testRunner({context, renderer});
runTestCases([
{
input: '{{nonce}}',
output: '',
},
], done);
});

it('should not render a nonce when security.nonce is falsy', function (done) {
const requestParams = {
security: {
nonce: ''
},
}
const renderer = buildRenderer({}, {}, {}, null, requestParams);
const runTestCases = testRunner({context, renderer});
runTestCases([
{
input: '{{nonce}}',
output: '',
},
], done);
});
});
9 changes: 9 additions & 0 deletions spec/helpers/stripQuerystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ describe('stripQuerystring helper', function() {
},
], done);
});

it('should return nothing when url is not a string', function(done) {
runTestCases([
{
input: '{{stripQuerystring 123}}',
output: '',
},
], done);
});
});
4 changes: 2 additions & 2 deletions spec/helpers/typeof.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ describe('typeof inline', () => {
});

it('should not accept more than one value, throw a error', function(done) {
renderString("{{typeof number string}}").catch(_ => {
renderString("{{typeof number string}}", context).catch(_ => {
done();
});
});

it('should not work as a block helper, throw a error', function(done) {
renderString("{{#typeof number}}").catch(_ => {
renderString("{{#typeof number}}content{{/typeof}}", context).catch(_ => {
done();
});
});
Expand Down
Loading