test: cases for async variables

This commit is contained in:
Harttle
2022-05-03 13:31:25 +08:00
committed by Harttle
parent 463a165e5e
commit 2f6d84befc
4 changed files with 17 additions and 6 deletions
+6
View File
@@ -142,4 +142,10 @@ describe('tags/if', function () {
const html = liquid.parseAndRenderSync(src, scope)
return expect(html).to.equal('true')
})
it('should support async variables', async () => {
const src = `{%if var == 'var' %}success{%endif%}`
const scope = { 'var': Promise.resolve('var') }
const html = await liquid.parseAndRender(src, scope)
return expect(html).to.equal('success')
})
})
+5
View File
@@ -52,6 +52,11 @@ describe('Liquid', function () {
const src = '{{ foo }}'
return expect(engine.parseAndRender(src, {}, { strictVariables: true })).rejectedWith(/undefined variable/)
})
it('should support async variables in output', async () => {
const src = '{{ foo }}'
const html = await engine.parseAndRender(src, { foo: Promise.resolve('FOO') })
expect(html).to.equal('FOO')
})
})
describe('#express()', function () {
const liquid = new Liquid({ root: '/root' })