mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: use drop valueOf when evaluated as condition (#705)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { Liquid, Drop } from '../../../src'
|
||||
|
||||
describe('tags/if', function () {
|
||||
const liquid = new Liquid()
|
||||
@@ -9,6 +9,12 @@ describe('tags/if', function () {
|
||||
emptyArray: []
|
||||
}
|
||||
|
||||
class BooleanDrop extends Drop {
|
||||
public valueOf () {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
it('should throw if not closed', function () {
|
||||
const src = '{% if false%}yes'
|
||||
return expect(liquid.parseAndRender(src, scope))
|
||||
@@ -143,6 +149,12 @@ describe('tags/if', function () {
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).toBe('success')
|
||||
})
|
||||
it('should support drop as condition variable', async () => {
|
||||
const src = `{% if drop %}yes{% else %}no{% endif %}`
|
||||
const scope = { drop: new BooleanDrop() }
|
||||
const html = await liquid.parseAndRender(src, scope)
|
||||
return expect(html).toBe('no')
|
||||
})
|
||||
it('should not render anything after an else branch even when first else branch is empty', () => {
|
||||
const engine = new Liquid()
|
||||
const result = engine.parseAndRenderSync('{% if false %}don\'t show' +
|
||||
|
||||
Reference in New Issue
Block a user