fix: coerce to Array in map and where filter

This commit is contained in:
harttle
2020-04-01 02:22:44 +08:00
parent d65ed408f0
commit c923598b40
12 changed files with 187 additions and 284 deletions
+8 -19
View File
@@ -3,25 +3,14 @@ import { expect } from 'chai'
export const liquid = new Liquid()
export const ctx = {
date: new Date(),
foo: 'bar',
arr: [-2, 'a'],
obj: { foo: 'bar' },
func: function () {}, // eslint-disable-line
posts: [{ category: 'foo' }, { category: 'bar' }],
products: [
{ title: 'Vacuum', type: 'living room' },
{ title: 'Spatula', type: 'kitchen' },
{ title: 'Television', type: 'living room' },
{ title: 'Garlic press', type: 'kitchen' },
{ title: 'Coffee mug', available: true },
{ title: 'Limited edition sneakers', available: false },
{ title: 'Boring sneakers', available: true }
]
export function render (src: string, ctx?: object) {
return liquid.parseAndRender(src, ctx)
}
export async function test (src: string, dst: string) {
const html = await liquid.parseAndRender(src, ctx)
return expect(html).to.equal(dst)
export async function test (src: string, ctx: object | string, dst?: string) {
if (dst === undefined) {
dst = ctx as string
ctx = {}
}
return expect(await render(src, ctx as object)).to.equal(dst)
}