tests for truthy

This commit is contained in:
harttle
2017-04-20 10:31:02 +08:00
parent 79815784c1
commit 07ec997ffd
+15
View File
@@ -5,6 +5,7 @@ var Scope = require('../src/scope.js');
var evalExp = syntax.evalExp;
var evalValue = syntax.evalValue;
var isTruthy = syntax.isTruthy;
describe('expression', function() {
var scope;
@@ -30,6 +31,20 @@ describe('expression', function() {
expect(evalValue('x', scope)).to.equal('XXX');
});
describe('.isTruthy()', function() {
// Spec: https://shopify.github.io/liquid/basics/truthy-and-falsy/
expect(isTruthy(true)).to.be.true;
expect(isTruthy(false)).to.be.false;
expect(isTruthy(null)).to.be.false;
expect(isTruthy('foo')).to.be.true;
expect(isTruthy('')).to.be.true;
expect(isTruthy(0)).to.be.true;
expect(isTruthy(1)).to.be.true;
expect(isTruthy(1.1)).to.be.true;
expect(isTruthy([1])).to.be.true;
expect(isTruthy([])).to.be.true;
})
describe('.evalExp()', function() {
it('should throw when scope undefined', function() {