mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
chore: migrate test cases from Chai to Jest
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import { Context } from '../context'
|
||||
import { HTMLToken, TagToken } from '../tokens'
|
||||
import { Render } from './render'
|
||||
import { Tag, HTML } from '../template'
|
||||
import { SimpleEmitter } from '../emitters'
|
||||
import { toPromise } from '../util'
|
||||
|
||||
describe('render', function () {
|
||||
let render: Render
|
||||
beforeEach(function () {
|
||||
render = new Render()
|
||||
})
|
||||
|
||||
describe('.renderTemplates()', function () {
|
||||
it('should render html', async function () {
|
||||
const scope = new Context()
|
||||
const token = { getContent: () => '<p>' } as HTMLToken
|
||||
const html = await toPromise(render.renderTemplates([new HTML(token)], scope, new SimpleEmitter()))
|
||||
return expect(html).toBe('<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).toBe('<p></p>')
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should render to html stream asyncly', function (done) {
|
||||
const scope = new Context()
|
||||
class CustomTag extends Tag {
|
||||
render () {
|
||||
return new Promise(
|
||||
resolve => setTimeout(() => resolve('async tag'), 10)
|
||||
)
|
||||
}
|
||||
}
|
||||
const tpls = [
|
||||
new HTML({ getContent: () => '<p>' } as HTMLToken),
|
||||
new CustomTag({ content: 'foo', args: '', name: 'foo' } as TagToken, [], {} 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).toBe('<p>async tag</p>')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user