mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
Added jsTruthy flag to constuctor in order to enable JS style truthiness evaluation
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { isTruthy } from '../../../src/render/boolean'
|
||||
import { isTruthy, isFalsy } from '../../../src/render/boolean'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('boolean', async function () {
|
||||
describe('boolean Shopify', async function () {
|
||||
describe('.isTruthy()', async function () {
|
||||
// Spec: https://shopify.github.io/liquid/basics/truthy-and-falsy/
|
||||
it('true is truthy', function () {
|
||||
@@ -36,3 +36,53 @@ describe('boolean', async function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('boolean jsTruthy', async function () {
|
||||
const ctx = {
|
||||
opts: {
|
||||
jsTruthy: true
|
||||
}
|
||||
}
|
||||
|
||||
describe('.isFalsy()', async function () {
|
||||
it('null is always falsy', function () {
|
||||
expect(isFalsy(null, ctx)).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
describe('.isTruthy()', async function () {
|
||||
it('true is truthy', function () {
|
||||
expect(isTruthy(true, ctx)).to.be.true
|
||||
})
|
||||
it('false is falsy', function () {
|
||||
expect(isTruthy(false, ctx)).to.be.false
|
||||
})
|
||||
it('null is always falsy', function () {
|
||||
expect(isTruthy(null, ctx)).to.be.false
|
||||
})
|
||||
it('null is always falsy', function () {
|
||||
expect(isTruthy(null, ctx)).to.be.false
|
||||
})
|
||||
it('"foo" is truthy', function () {
|
||||
expect(isTruthy('foo', ctx)).to.be.true
|
||||
})
|
||||
it('"" is falsy', function () {
|
||||
expect(isTruthy('', ctx)).to.be.false
|
||||
})
|
||||
it('0 is falsy', function () {
|
||||
expect(isTruthy(0, ctx)).to.be.false
|
||||
})
|
||||
it('1 is truthy', function () {
|
||||
expect(isTruthy(1, ctx)).to.be.true
|
||||
})
|
||||
it('1.1 is truthy', function () {
|
||||
expect(isTruthy(1.1, ctx)).to.be.true
|
||||
})
|
||||
it('[1] is truthy', function () {
|
||||
expect(isTruthy([1], ctx)).to.be.true
|
||||
})
|
||||
it('[] is falsy', function () {
|
||||
expect(isTruthy([], ctx)).to.be.false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user