mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 21:40:39 -07:00
feat: promise support for drops, working on #65
This commit is contained in:
@@ -33,9 +33,9 @@ describe('filters/array', function () {
|
||||
' | split: ", " %}{{ my_array | size }}',
|
||||
'4')
|
||||
})
|
||||
it('should also be used with dot notation - string',
|
||||
it('should be respected with <string>.size notation',
|
||||
() => test('{% assign my_string = "Ground control to Major Tom." %}{{ my_string.size }}', '28'))
|
||||
it('should also be used with dot notation - array',
|
||||
it('should be respected with <array>.size notation',
|
||||
() => test('{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}{{ my_array.size }}', '4'))
|
||||
})
|
||||
describe('slice', function () {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Liquid from '../../../../src/liquid'
|
||||
import { expect, use } from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { Context } from '../../../../src/scope/scope'
|
||||
import { Context } from '../../../../src/scope/context'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ describe('drop/drop', function () {
|
||||
class CustomDrop extends Liquid.Types.Drop {
|
||||
name: string = 'NAME'
|
||||
getName () {
|
||||
return 'GETNAME'
|
||||
return 'GET NAME'
|
||||
}
|
||||
}
|
||||
class CustomDropWithMethodMissing extends CustomDrop {
|
||||
@@ -16,9 +16,18 @@ describe('drop/drop', function () {
|
||||
return key.toUpperCase()
|
||||
}
|
||||
}
|
||||
class PromiseDrop extends Liquid.Types.Drop {
|
||||
name = Promise.resolve('NAME')
|
||||
async getName () {
|
||||
return 'GET NAME'
|
||||
}
|
||||
async liquidMethodMissing (key: string) {
|
||||
return key.toUpperCase()
|
||||
}
|
||||
}
|
||||
it('should call corresponding method', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.getName}}`, { obj: new CustomDrop() })
|
||||
expect(html).to.equal('GETNAME')
|
||||
expect(html).to.equal('GET NAME')
|
||||
})
|
||||
it('should read corresponding property', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.name}}`, { obj: new CustomDrop() })
|
||||
@@ -32,4 +41,16 @@ describe('drop/drop', function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new CustomDropWithMethodMissing() })
|
||||
expect(html).to.equal('FOO')
|
||||
})
|
||||
it('should call corresponding promise method', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.getName}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('GET NAME')
|
||||
})
|
||||
it('should read corresponding promise property', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.name}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('NAME')
|
||||
})
|
||||
it('should support promise returned by liquidMethodMissing', async function () {
|
||||
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new PromiseDrop() })
|
||||
expect(html).to.equal('FOO')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user