mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
* spelling: according Signed-off-by: Josh Soref <[email protected]> * spelling: asynchronously Signed-off-by: Josh Soref <[email protected]> * spelling: background Signed-off-by: Josh Soref <[email protected]> * spelling: camel Signed-off-by: Josh Soref <[email protected]> * spelling: cannot Signed-off-by: Josh Soref <[email protected]> * spelling: case-sensitive Signed-off-by: Josh Soref <[email protected]> * spelling: comparison Signed-off-by: Josh Soref <[email protected]> * spelling: demos Signed-off-by: Josh Soref <[email protected]> * spelling: forloop Signed-off-by: Josh Soref <[email protected]> * spelling: formatters Signed-off-by: Josh Soref <[email protected]> * spelling: github Signed-off-by: Josh Soref <[email protected]> * spelling: guidelines Signed-off-by: Josh Soref <[email protected]> * spelling: hashes Signed-off-by: Josh Soref <[email protected]> * spelling: https Signed-off-by: Josh Soref <[email protected]> * spelling: javascript Signed-off-by: Josh Soref <[email protected]> * spelling: keep Signed-off-by: Josh Soref <[email protected]> * spelling: natural Signed-off-by: Josh Soref <[email protected]> * spelling: neither Signed-off-by: Josh Soref <[email protected]> * spelling: no longer Signed-off-by: Josh Soref <[email protected]> * spelling: nonexistent Signed-off-by: Josh Soref <[email protected]> * spelling: output Signed-off-by: Josh Soref <[email protected]> * spelling: polymorphism Signed-off-by: Josh Soref <[email protected]> * spelling: precache Signed-off-by: Josh Soref <[email protected]> * spelling: programmatically Signed-off-by: Josh Soref <[email protected]> * spelling: punctuation Signed-off-by: Josh Soref <[email protected]> * spelling: registration Signed-off-by: Josh Soref <[email protected]> * spelling: rendered Signed-off-by: Josh Soref <[email protected]> * spelling: synchronously Signed-off-by: Josh Soref <[email protected]> * spelling: thrown Signed-off-by: Josh Soref <[email protected]> * spelling: trimmed Signed-off-by: Josh Soref <[email protected]> * spelling: unbalanced Signed-off-by: Josh Soref <[email protected]> * chore: use example.com * chore: fix reference for sidebar.registration --------- Signed-off-by: Josh Soref <[email protected]> Co-authored-by: Harttle <[email protected]>
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import { Liquid } from '../..'
|
|
|
|
describe('.parseAndRender()', function () {
|
|
var engine: Liquid, strictEngine: Liquid
|
|
beforeEach(function () {
|
|
engine = new Liquid()
|
|
strictEngine = new Liquid({
|
|
strictFilters: true
|
|
})
|
|
})
|
|
it('should stringify array ', async function () {
|
|
var ctx = { arr: [-2, 'a'] }
|
|
const html = await engine.parseAndRender('{{arr}}', ctx)
|
|
return expect(html).toBe('-2a')
|
|
})
|
|
it('should render undefined as empty', async function () {
|
|
const html = await engine.parseAndRender('foo{{zzz}}bar', {})
|
|
return expect(html).toBe('foobar')
|
|
})
|
|
it('should render as null when filter undefined', async function () {
|
|
const html = await engine.parseAndRender('{{"foo" | filter1}}', {})
|
|
return expect(html).toBe('foo')
|
|
})
|
|
it('should throw upon undefined filter when strictFilters set', function () {
|
|
return expect(strictEngine.parseAndRender('{{"foo" | filter1}}', {})).rejects.toThrow(/undefined filter: filter1/)
|
|
})
|
|
it('should parse html', function () {
|
|
expect(function () {
|
|
engine.parse('{{obj}}')
|
|
}).not.toThrow()
|
|
expect(function () {
|
|
engine.parse('<html><head>{{obj}}</head></html>')
|
|
}).not.toThrow()
|
|
})
|
|
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).toBe('12')
|
|
const result2 = await engine.render(template, ctx)
|
|
expect(result2).toBe('12')
|
|
})
|
|
it('should support the "join" filter', async function () {
|
|
var ctx = { names: ['alice', 'bob'] }
|
|
var template = engine.parse('<p>{{names | join: ","}}</p>')
|
|
const html = await engine.render(template, ctx)
|
|
return expect(html).toBe('<p>alice,bob</p>')
|
|
})
|
|
it('should support the "first" filter', async function () {
|
|
var src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
|
|
'{{ my_array | first }}'
|
|
const html = await engine.parseAndRender(src)
|
|
return expect(html).toBe('apples')
|
|
})
|
|
it('should support nil(null, undefined) literal', async function () {
|
|
const src = '{% if nonexistent == nil %}true{% endif %}'
|
|
const html = await engine.parseAndRender(src)
|
|
expect(html).toBe('true')
|
|
})
|
|
})
|