mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
refactor: static strict_filters, disable settigns when rendering
This commit is contained in:
+1
-2
@@ -14,10 +14,9 @@ describe('filter', function() {
|
||||
filter.clear();
|
||||
scope = Scope.factory();
|
||||
});
|
||||
it('should return undefined when not registered', function() {
|
||||
it('should return default filter when not registered', function() {
|
||||
var result = filter.construct('foo');
|
||||
expect(result.name).to.equal('foo');
|
||||
expect(result.error).to.be.an('Error');
|
||||
});
|
||||
|
||||
it('should throw when filter name illegal', function() {
|
||||
|
||||
+8
-6
@@ -5,7 +5,7 @@ const mock = require('mock-fs');
|
||||
chai.use(require("chai-as-promised"));
|
||||
|
||||
describe('liquid', function() {
|
||||
var engine, ctx;
|
||||
var engine, strictEngine, ctx;
|
||||
beforeEach(function() {
|
||||
ctx = {
|
||||
name: 'harttle',
|
||||
@@ -18,6 +18,11 @@ describe('liquid', function() {
|
||||
root: '/root/',
|
||||
extname: '.html'
|
||||
});
|
||||
strictEngine = Liquid({
|
||||
root: '/root',
|
||||
extname: '.html',
|
||||
strict_filters: true
|
||||
});
|
||||
mock({
|
||||
'/root/files/foo.html': 'foo',
|
||||
'/root/files/name.html': 'My name is {{name}}.',
|
||||
@@ -40,13 +45,10 @@ describe('liquid', function() {
|
||||
return engine.parseAndRender('foo{{zzz}}bar', ctx).should.eventually.equal('foobar');
|
||||
});
|
||||
it('should render as null when filter undefined', function() {
|
||||
return engine.parseAndRender('{{arr | filter1}}', ctx).should.eventually.equal('');
|
||||
return engine.parseAndRender('{{"foo" | filter1}}', ctx).should.eventually.equal('foo');
|
||||
});
|
||||
it('should throw upon undefined filter when strict_filters set', function() {
|
||||
var opts = {
|
||||
strict_filters: true
|
||||
};
|
||||
return expect(engine.parseAndRender('{{arr | filter1}}', ctx, opts)).to
|
||||
return expect(strictEngine.parseAndRender('{{arr | filter1}}', ctx)).to
|
||||
.be.rejectedWith(/undefined filter: filter1/);
|
||||
});
|
||||
});
|
||||
|
||||
+8
-8
@@ -130,14 +130,6 @@ describe('error', function() {
|
||||
expect(e.message).to.contain('undefined variable: a');
|
||||
});
|
||||
});
|
||||
it('should throw RenderError when filter not defined', function() {
|
||||
return expect(strictEngine.parseAndRender('{{1 | a}}')).to.eventually
|
||||
.be.rejected
|
||||
.then(function(e) {
|
||||
expect(e).to.have.property('name', 'RenderError');
|
||||
expect(e.message).to.contain('undefined filter: a');
|
||||
});
|
||||
});
|
||||
it('should contain template content in err.message', function() {
|
||||
var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'];
|
||||
var message = [
|
||||
@@ -207,6 +199,14 @@ describe('error', function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
it('should throw RenderError when filter not defined', function() {
|
||||
return expect(strictEngine.parseAndRender('{{1 | a}}')).to.eventually
|
||||
.be.rejected
|
||||
.then(function(e) {
|
||||
expect(e).to.have.property('name', 'ParseError');
|
||||
expect(e.message).to.contain('undefined filter: a');
|
||||
});
|
||||
});
|
||||
it('should throw ParseError when tag not closed', function() {
|
||||
return expect(engine.parseAndRender('{% if %}')).to.eventually
|
||||
.be.rejected
|
||||
|
||||
Reference in New Issue
Block a user