refactor unit test for tags/unless

This commit is contained in:
harttle
2016-11-06 15:42:30 +08:00
parent f3d69fbc6e
commit e9ff3d916d
+10 -5
View File
@@ -6,23 +6,28 @@ chai.use(require("chai-as-promised"));
describe('tags/unless', function() {
var liquid = Liquid();
it('should support unless 1', function() {
it('should render else when predicate yields true', function() {
var src = '{% unless 1 %}yes{%else%}no{%endunless%}';
return expect(liquid.parseAndRender(src))
.to.eventually.equal('no');
});
it('should support unless 2', function() {
it('should render unless when predicate yields false', function() {
var src = '{% unless 0 %}yes{%else%}no{%endunless%}';
return expect(liquid.parseAndRender(src))
.to.eventually.equal('yes');
});
it('should reject when tag not closed', function() {
var src = '{% unless 1>2 %}yes';
return expect(liquid.parseAndRender(src))
.to.be.rejectedWith(/tag {% unless 1>2 %} not closed/);
});
it('should support unless 3', function() {
it('should render unless when predicate yields false and else undefined', function() {
var src = '{% unless 1>2 %}yes{%endunless%}';
return expect(liquid.parseAndRender(src))
.to.eventually.equal('yes');
});
it('should support unless 4', function() {
var src = '{% unless true %}{%endunless%}';
it('should render "" when predicate yields false and else undefined', function() {
var src = '{% unless 1<2 %}yes{%endunless%}';
return expect(liquid.parseAndRender(src))
.to.eventually.equal('');
});