mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 21:40:39 -07:00
@@ -3,8 +3,10 @@ import { Context } from '../../../src/context/context'
|
||||
import { HTMLToken } from '../../../src/tokens/html-token'
|
||||
import { Render } from '../../../src/render/render'
|
||||
import { HTML } from '../../../src/template/html'
|
||||
import { Emitter } from '../../../src/render/emitter'
|
||||
import { SimpleEmitter } from '../../../src/emitters/simple-emitter'
|
||||
import { toThenable } from '../../../src/util/async'
|
||||
import { Tag } from '../../../src/template/tag/tag'
|
||||
import { TagToken } from '../../../src/types'
|
||||
|
||||
describe('render', function () {
|
||||
let render: Render
|
||||
@@ -16,8 +18,52 @@ describe('render', function () {
|
||||
it('should render html', async function () {
|
||||
const scope = new Context()
|
||||
const token = { getContent: () => '<p>' } as HTMLToken
|
||||
const html = await toThenable(render.renderTemplates([new HTML(token)], scope, new Emitter(scope.opts.keepOutputType)))
|
||||
const html = await toThenable(render.renderTemplates([new HTML(token)], scope, new SimpleEmitter()))
|
||||
return expect(html).to.equal('<p>')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.renderTemplatesToNodeStream()', function () {
|
||||
it('should render to html stream', function (done) {
|
||||
const scope = new Context()
|
||||
const tpls = [
|
||||
new HTML({ getContent: () => '<p>' } as HTMLToken),
|
||||
new HTML({ getContent: () => '</p>' } as HTMLToken)
|
||||
]
|
||||
const stream = render.renderTemplatesToNodeStream(tpls, scope)
|
||||
let result = ''
|
||||
stream.on('data', (data) => {
|
||||
result += data
|
||||
})
|
||||
stream.on('end', () => {
|
||||
expect(result).to.equal('<p></p>')
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should render to html stream asyncly', function (done) {
|
||||
const scope = new Context()
|
||||
const tpls = [
|
||||
new HTML({ getContent: () => '<p>' } as HTMLToken),
|
||||
new Tag({ content: 'foo', args: '', name: 'foo' } as TagToken, [], {
|
||||
tags: {
|
||||
get: () => ({
|
||||
render: () => new Promise(
|
||||
resolve => setTimeout(() => resolve('async tag'), 10)
|
||||
)
|
||||
})
|
||||
}
|
||||
} as any),
|
||||
new HTML({ getContent: () => '</p>' } as HTMLToken)
|
||||
]
|
||||
const stream = render.renderTemplatesToNodeStream(tpls, scope)
|
||||
let result = ''
|
||||
stream.on('data', (data) => {
|
||||
result += data
|
||||
})
|
||||
stream.on('end', () => {
|
||||
expect(result).to.equal('<p>async tag</p>')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user