Skip to content

Commit de0be4a

Browse files
author
Daniel Clausmeyer
committed
test: add test for options.expressions.locals pollution
1 parent ccf454a commit de0be4a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/extend.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,37 @@ describe('Extend', () => {
426426
return init(page3, {strict: false})
427427
.then(html => expect(html).toBe(want));
428428
});
429+
430+
/*
431+
This plugin merges the locals from options.expressions.locals and the
432+
"locals" attribute into the options.expressions.locals property. Arrays in
433+
the attribute locals will be copied into options.expressions.locals and when
434+
the plugin is called again they will be merged again, doubling all array
435+
entries every time the plugin is called.
436+
*/
437+
it('should not pollute options.expression.locals ', async () => {
438+
mfs.writeFileSync('./base.html', `<div class="base">{{ list.join(", ") }}</div>`);
439+
440+
const options = {
441+
expressions: {
442+
locals: {}
443+
}
444+
};
445+
446+
const preHtml = `
447+
<extends src="base.html" locals='{"list": ["One", "Two", "Three"]}'>
448+
</extends>
449+
`;
450+
const postHtml = `<div class="base">One, Two, Three</div>`;
451+
452+
expect(await init(preHtml, options)).toBe(postHtml);
453+
expect(options.expressions.locals).toStrictEqual({});
454+
/*
455+
Since the entries in "list" have been merged with themselves, the content
456+
would be "One, Two, Three, One, Two, Three"
457+
*/
458+
expect(await init(preHtml, options)).toBe(postHtml);
459+
});
429460
});
430461

431462
describe('Messages', () => {

0 commit comments

Comments
 (0)