mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
test: add tests for keepOutputType option
This commit is contained in:
committed by
Jun Yang
parent
cd92e77726
commit
b8e4b3337b
@@ -4,6 +4,7 @@ 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'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
@@ -42,4 +43,55 @@ describe('Output', function () {
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
context('when keepOutputType is enabled', () => {
|
||||
const emitter: any = {
|
||||
write: (html: any) => {
|
||||
if (emitter.keepOutputType && typeof html !== 'string') {
|
||||
emitter.html = html
|
||||
} else {
|
||||
emitter.html += html as string
|
||||
}
|
||||
},
|
||||
html: '',
|
||||
keepOutputType: true
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
filters = new FilterMap(false, liquid)
|
||||
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)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal(42)
|
||||
})
|
||||
it('should respect output variable boolean type', async () => {
|
||||
const scope = new Context({
|
||||
foo: true
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal(true)
|
||||
})
|
||||
it('should respect output variable object type', async () => {
|
||||
const scope = new Context({
|
||||
foo: 'test'
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.equal('test')
|
||||
})
|
||||
it('should respect output variable string type', async () => {
|
||||
const scope = new Context({
|
||||
foo: { a: { b: 42 } }
|
||||
}, { ...defaultOptions, keepOutputType: true })
|
||||
const output = new Output({ content: 'foo' } as OutputToken, filters, liquid)
|
||||
await toThenable(output.render(scope, emitter))
|
||||
return expect(emitter.html).to.deep.equal({ a: { b: 42 } })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user