Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
/ commons-server Public archive

Commit

Permalink
Add tests for split helper, set version 2.13.0
Browse files Browse the repository at this point in the history
Guillaume committed Nov 11, 2021
1 parent e7be455 commit 732a5b8
Showing 4 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mockoon/commons-server",
"description": "Mockoon's commons server library. Used in Mockoon desktop application and CLI.",
"version": "2.12.0",
"version": "2.13.0",
"author": {
"name": "Guillaume Monnet",
"email": "[email protected]",
2 changes: 1 addition & 1 deletion src/libs/templating-helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -335,7 +335,7 @@ export const Helpers = {
sliceTo?: number | unknown
) {
if (!(arr instanceof Array)) {
return 'lol';
return '';
}

return typeof sliceTo === 'number'
42 changes: 42 additions & 0 deletions test/templating-helpers/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -448,6 +448,48 @@ describe('Template parser', () => {
});
});

describe('Helper: slice', () => {
it('should return an empty string if parameter is not an array', () => {
const parseResult = TemplateParser(
'{{slice "hello"}}',
{} as any,
{} as any
);

expect(parseResult).to.be.equal('');
});

it('should return the stringified array (same content)', () => {
const parseResult = TemplateParser(
'{{slice (array "Mockoon" "is" "very" "nice")}}',
{} as any,
{} as any
);

expect(parseResult).to.be.equal('Mockoon,is,very,nice');
});

it('should return the stringified first two elements', () => {
const parseResult = TemplateParser(
'{{slice (array "Mockoon" "is" "very" "nice") 0 2}}',
{} as any,
{} as any
);

expect(parseResult).to.be.equal('Mockoon,is');
});

it('should return the stringified last two elements', () => {
const parseResult = TemplateParser(
'{{slice (array "Mockoon" "is" "very" "nice") 2}}',
{} as any,
{} as any
);

expect(parseResult).to.be.equal('very,nice');
});
});

describe('Helper: indexOf', () => {
it('should return the index of a matching substring', () => {
const parseResult = TemplateParser(

0 comments on commit 732a5b8

Please sign in to comment.