mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
feat: exported Drop interface for #107
Deprecate snake_cased options and APIs, sed #109
This commit is contained in:
+27
-14
@@ -4,25 +4,38 @@ import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
use(chaiAsPromised)
|
||||
|
||||
class SettingsDrop extends Liquid.Types.Drop {
|
||||
foo: string = 'FOO'
|
||||
bar() {
|
||||
return 'BAR'
|
||||
}
|
||||
liquidMethodMissing(key: string) {
|
||||
return key.toUpperCase()
|
||||
}
|
||||
}
|
||||
|
||||
describe('drop', function () {
|
||||
var engine: Liquid
|
||||
const settings = new SettingsDrop()
|
||||
let engine: Liquid
|
||||
beforeEach(function () {
|
||||
engine = new Liquid()
|
||||
})
|
||||
it('should support liquid_method_missing', async function () {
|
||||
it('should support liquidMethodMissing', async function () {
|
||||
let i = 0
|
||||
const src = `{{settings.foo}},{{settings.foo}},{{settings.foo}}`
|
||||
const ctx = { settings: { liquid_method_missing: () => i++ } }
|
||||
const html = await engine.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('0,1,2')
|
||||
const src = `{{settings.foo}},{{settings.bar}},{{settings.coo}}`
|
||||
const html = await engine.parseAndRender(src, { settings })
|
||||
return expect(html).to.equal('FOO,BAR,COO')
|
||||
})
|
||||
it('should test blank strings', async function () {
|
||||
const src = `
|
||||
{% unless settings.fp_heading == blank %}
|
||||
<h1>{{ settings.fp_heading }}</h1>
|
||||
{% endunless %}`
|
||||
var ctx = { settings: { fp_heading: '' } }
|
||||
const html = await engine.parseAndRender(src, ctx)
|
||||
return expect(html).to.match(/^\s+$/)
|
||||
|
||||
describe('BlandDrop', function () {
|
||||
it('should test blank strings', async function () {
|
||||
const src = `
|
||||
{% unless settings.fp_heading == blank %}
|
||||
<h1>{{ settings.fp_heading }}</h1>
|
||||
{% endunless %}`
|
||||
var ctx = { settings: { fp_heading: '' } }
|
||||
const html = await engine.parseAndRender(src, ctx)
|
||||
return expect(html).to.match(/^\s+$/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,18 +9,13 @@ describe('.parseAndRender()', function () {
|
||||
beforeEach(function () {
|
||||
engine = new Liquid()
|
||||
strictEngine = new Liquid({
|
||||
strict_filters: true
|
||||
strictFilters: true
|
||||
})
|
||||
})
|
||||
it('should stringify object', async function () {
|
||||
var ctx = { obj: { foo: 'bar' } }
|
||||
const html = await engine.parseAndRender('{{obj}}', ctx)
|
||||
return expect(html).to.equal('{"foo":"bar"}')
|
||||
})
|
||||
it('should stringify array ', async function () {
|
||||
var ctx = { arr: [-2, 'a'] }
|
||||
const html = await engine.parseAndRender('{{arr}}', ctx)
|
||||
return expect(html).to.equal('[-2,"a"]')
|
||||
return expect(html).to.equal('-2,a')
|
||||
})
|
||||
it('should render undefined as empty', async function () {
|
||||
const html = await engine.parseAndRender('foo{{zzz}}bar', {})
|
||||
@@ -30,7 +25,7 @@ describe('.parseAndRender()', function () {
|
||||
const html = await engine.parseAndRender('{{"foo" | filter1}}', {})
|
||||
return expect(html).to.equal('foo')
|
||||
})
|
||||
it('should throw upon undefined filter when strict_filters set', function () {
|
||||
it('should throw upon undefined filter when strictFilters set', function () {
|
||||
return expect(strictEngine.parseAndRender('{{"foo" | filter1}}', {})).to
|
||||
.be.rejectedWith(/undefined filter: filter1/)
|
||||
})
|
||||
@@ -42,13 +37,13 @@ describe('.parseAndRender()', function () {
|
||||
engine.parse('<html><head>{{obj}}</head></html>')
|
||||
}).to.not.throw()
|
||||
})
|
||||
it('should render template multiple times', async function () {
|
||||
const ctx = { obj: { foo: 'bar' } }
|
||||
it('template should be able to be rendered multiple times', async function () {
|
||||
const ctx = { obj: [1, 2] }
|
||||
const template = engine.parse('{{obj}}')
|
||||
const result = await engine.render(template, ctx)
|
||||
expect(result).to.equal('{"foo":"bar"}')
|
||||
expect(result).to.equal('1,2')
|
||||
const result2 = await engine.render(template, ctx)
|
||||
expect(result2).to.equal('{"foo":"bar"}')
|
||||
expect(result2).to.equal('1,2')
|
||||
})
|
||||
it('should render filters', async function () {
|
||||
var ctx = { names: ['alice', 'bob'] }
|
||||
|
||||
Reference in New Issue
Block a user