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
+3 -3
View File
@@ -2662,9 +2662,9 @@
}
},
"caniuse-lite": {
"version": "1.0.30001312",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz",
"integrity": "sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==",
"version": "1.0.30001335",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001335.tgz",
"integrity": "sha512-ddP1Tgm7z2iIxu6QTtbZUv6HJxSaV/PZeSrWFZtbY4JZ69tOeNhBCl3HyRQgeNZKE5AOn1kpV7fhljigy0Ty3w==",
"dev": true
},
"cardinal": {
+3 -3
View File
@@ -25,9 +25,9 @@ export class Expression {
const operands: any[] = []
for (const token of this.postfix) {
if (TypeGuards.isOperatorToken(token)) {
const r = yield operands.pop()
const l = yield operands.pop()
const result = evalOperatorToken(ctx.opts.operators, token, l, r, ctx)
const r = operands.pop()
const l = operands.pop()
const result = yield evalOperatorToken(ctx.opts.operators, token, l, r, ctx)
operands.push(result)
} else {
operands.push(yield evalToken(token, ctx, lenient && this.postfix.length === 1))
+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' })