mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
feat: support filters in if/unless/case, see #287
This commit is contained in:
@@ -3,7 +3,6 @@ import { toThenable } from '../../../src/util/async'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Output } from '../../../src/template/output'
|
||||
import { OutputToken } from '../../../src/tokens/output-token'
|
||||
import { FilterMap } from '../../../src/template/filter/filter-map'
|
||||
import { defaultOptions } from '../../../src/liquid-options'
|
||||
import { createTrie } from '../../../src/util/operator-trie'
|
||||
import { defaultOperators } from '../../../src/types'
|
||||
@@ -15,35 +14,31 @@ describe('Output', function () {
|
||||
const liquid = {
|
||||
options: { operatorsTrie: createTrie(defaultOperators) }
|
||||
} as any
|
||||
let filters: FilterMap
|
||||
beforeEach(function () {
|
||||
filters = new FilterMap(false, liquid)
|
||||
emitter.html = ''
|
||||
})
|
||||
beforeEach(() => { emitter.html = '' })
|
||||
|
||||
it('should stringify objects', async function () {
|
||||
const scope = new Context({
|
||||
foo: { obj: { arr: ['a', 2] } }
|
||||
})
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'foo' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('[object Object]')
|
||||
})
|
||||
it('should skip function property', async function () {
|
||||
const scope = new Context({ obj: { foo: 'foo', bar: (x: any) => x } })
|
||||
const output = new Output({ content: 'obj' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'obj' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('[object Object]')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = new Context({ obj: { toString: () => 'FOO' } })
|
||||
const output = new Output({ content: 'obj' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'obj' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = new Context({ obj: { toString: () => 'FOO' } })
|
||||
const output = new Output({ content: 'obj' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'obj' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
@@ -60,16 +55,13 @@ describe('Output', function () {
|
||||
keepOutputType: true
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
filters = new FilterMap(false, liquid)
|
||||
emitter.html = ''
|
||||
})
|
||||
beforeEach(() => { emitter.html = '' })
|
||||
|
||||
it('should respect output variable number type', async () => {
|
||||
const scope = new Context({
|
||||
foo: 42
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'foo' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal(42)
|
||||
})
|
||||
@@ -77,7 +69,7 @@ describe('Output', function () {
|
||||
const scope = new Context({
|
||||
foo: true
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'foo' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal(true)
|
||||
})
|
||||
@@ -85,7 +77,7 @@ describe('Output', function () {
|
||||
const scope = new Context({
|
||||
foo: 'test'
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'foo' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('test')
|
||||
})
|
||||
@@ -93,7 +85,7 @@ describe('Output', function () {
|
||||
const scope = new Context({
|
||||
foo: { a: { b: 42 } }
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
const output = new Output({ content: 'foo' } as OutputToken, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.deep.equal({ a: { b: 42 } })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user