Skip to content

Commit

Permalink
fix: add tests for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
learosema committed Sep 30, 2024
1 parent 78947c4 commit 0ae3689
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/transforms/template-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ describe('template function', () => {
const result = template('{{greeting | shout }}')({greeting: "Hello"}, filters);

assert.equal(result, "HELLO");
})
});

it('should be able to apply a filter with additional parameters', () => {
const data = { greeting: 'Hello Lea'}
const filters = new Map();
filters.set('piratify', (str, prefix = 'Yo-ho-ho', suffix = 'yarrr') => `${prefix}! ${str}, ${suffix}!`);

assert.equal(template('{{ greeting | piratify }}')(data, filters), 'Yo-ho-ho! Hello Lea, yarrr!');
assert.equal(template('{{ greeting | piratify: "AYE" }}')(data, filters), 'AYE! Hello Lea, yarrr!');
assert.equal(template('{{ greeting | piratify: "Ahoy", "matey" }}')(data, filters), 'Ahoy! Hello Lea, matey!');
});
});

describe('handleTemplateFile function', () => {
Expand Down

0 comments on commit 0ae3689

Please sign in to comment.