mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
test: cases for TagMap
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { expect } from 'chai'
|
||||
import { TagMap } from '../../../src/template/tag/tag-map'
|
||||
|
||||
describe('TagMap', function () {
|
||||
it('should throw when not exist', function () {
|
||||
const map = new TagMap()
|
||||
expect(() => map.get('not-exist'))
|
||||
.to.throw(/tag "not-exist" not found/)
|
||||
})
|
||||
it('should get previously set value', function () {
|
||||
const map = new TagMap()
|
||||
const impl = { render: () => 'foo' }
|
||||
map.set('foo', impl)
|
||||
expect(map.get('foo')).to.equal(impl)
|
||||
})
|
||||
})
|
||||
@@ -3,7 +3,6 @@ import { Tag } from '../../../src/template/tag/tag'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import * as sinon from 'sinon'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { TagToken } from '../../../src/parser/tag-token'
|
||||
import { toThenable } from '../../../src/util/async'
|
||||
|
||||
@@ -11,50 +10,22 @@ chai.use(sinonChai)
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Tag', function () {
|
||||
let ctx: Context
|
||||
let liquid: Liquid
|
||||
const ctx = new Context()
|
||||
const emitter: any = { write: (html: string) => (emitter.html += html), html: '' }
|
||||
before(function () {
|
||||
ctx = new Context({
|
||||
foo: 'bar',
|
||||
arr: [2, 1],
|
||||
bar: {
|
||||
coo: 'uoo'
|
||||
}
|
||||
})
|
||||
liquid = new Liquid()
|
||||
})
|
||||
beforeEach(function () {
|
||||
emitter.html = ''
|
||||
})
|
||||
|
||||
it('should throw when not registered', function () {
|
||||
expect(function () {
|
||||
new Tag({ // eslint-disable-line
|
||||
type: 'tag',
|
||||
content: 'foo',
|
||||
args: '',
|
||||
name: 'not-exist'
|
||||
} as TagToken, [], liquid)
|
||||
}).to.throw(/tag "not-exist" not found/)
|
||||
})
|
||||
|
||||
it('should register simple tag', function () {
|
||||
expect(function () {
|
||||
liquid.registerTag('foo', { render: () => 'bar' })
|
||||
}).not.throw()
|
||||
})
|
||||
|
||||
it('should call tag.render', async function () {
|
||||
const spy = sinon.spy()
|
||||
liquid.registerTag('foo', { render: spy })
|
||||
const token = {
|
||||
type: 'tag',
|
||||
content: 'foo',
|
||||
args: '',
|
||||
name: 'foo'
|
||||
} as TagToken
|
||||
await toThenable(new Tag(token, [], liquid).render(ctx, emitter))
|
||||
await toThenable(new Tag(token, [], {
|
||||
tags: {
|
||||
get: () => ({ render: spy })
|
||||
}
|
||||
} as any).render(ctx, emitter))
|
||||
expect(spy).to.have.been.called
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user