mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix string type checking and circular reference, working on #81
This commit is contained in:
+41
-2
@@ -17,11 +17,17 @@ describe('render', function () {
|
||||
var scope, render
|
||||
|
||||
beforeEach(function () {
|
||||
scope = Scope.factory({
|
||||
var ctx = {
|
||||
foo: {
|
||||
bar: ['a', 2]
|
||||
},
|
||||
bar: {
|
||||
to_liquid: x => 'custom'
|
||||
}
|
||||
})
|
||||
}
|
||||
ctx.self = ctx
|
||||
|
||||
scope = Scope.factory(ctx)
|
||||
filter.clear()
|
||||
tag.clear()
|
||||
render = Render()
|
||||
@@ -39,6 +45,34 @@ describe('render', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('.renderValue()', function () {
|
||||
it('should respect to .to_liquid() method', function () {
|
||||
var tpl = Template.parseValue('bar')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('custom')
|
||||
})
|
||||
|
||||
it('should stringify objects', function () {
|
||||
let scope = Scope.factory({
|
||||
foo: { obj: { arr: ['a', 2] } }
|
||||
})
|
||||
let tpl = Template.parseValue('foo')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"obj":{"arr":["a",2]}}')
|
||||
})
|
||||
it('should skip circular property', function () {
|
||||
let ctx = { foo: { num: 2 }, bar: 'bar' }
|
||||
ctx.foo.circular = ctx
|
||||
|
||||
let scope = Scope.factory(ctx)
|
||||
let tpl = Template.parseValue('foo')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"num":2,"circular":{"bar":"bar"}}')
|
||||
})
|
||||
it('should skip function property', function () {
|
||||
let scope = Scope.factory({obj: {foo: 'foo', bar: x => x}})
|
||||
let tpl = Template.parseValue('obj')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"foo":"foo"}')
|
||||
})
|
||||
})
|
||||
|
||||
it('should eval filter with correct arguments', function () {
|
||||
var date = sinon.stub().returns('y')
|
||||
var time = sinon.spy()
|
||||
@@ -62,5 +96,10 @@ describe('render', function () {
|
||||
var tpl = Template.parseValue('foo.bar[0] | date: "b" | time:2')
|
||||
expect(render.evalValue(tpl, scope)).to.equal('ab6')
|
||||
})
|
||||
it('should reserve type', function () {
|
||||
filter.register('arr', () => [1])
|
||||
var tpl = Template.parseValue('"x" | arr')
|
||||
expect(render.evalValue(tpl, scope)).to.deep.equal([1])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user