feature: variable lookup respects to to_liquid, #81

This commit is contained in:
harttle
2018-08-14 00:11:50 +08:00
committed by Jun Yang
parent ea38a9e1f5
commit 5b43520d78
4 changed files with 35 additions and 22 deletions
+14 -15
View File
@@ -1,3 +1,4 @@
'use strict'
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
@@ -42,7 +43,6 @@ describe('render', function () {
let 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] } }
@@ -65,20 +65,6 @@ describe('render', function () {
})
})
it('should eval filter with correct arguments', function () {
let date = sinon.stub().returns('y')
let time = sinon.spy()
filter.register('date', date)
filter.register('time', time)
let tpl = Template.parseValue('foo.bar | date: "b" | time:2')
let scope = Scope.factory({
foo: {bar: 'bar'}
})
render.evalValue(tpl, scope)
expect(date).to.have.been.calledWith('bar', 'b')
expect(time).to.have.been.calledWith('y', 2)
})
describe('.evalValue()', function () {
it('should throw when scope undefined', function () {
expect(function () {
@@ -99,5 +85,18 @@ describe('render', function () {
let tpl = Template.parseValue('"x" | arr')
expect(render.evalValue(tpl, Scope.factory())).to.deep.equal([1])
})
it('should eval filter with correct arguments', function () {
let date = sinon.stub().returns('y')
let time = sinon.spy()
filter.register('date', date)
filter.register('time', time)
let tpl = Template.parseValue('foo.bar | date: "b" | time:2')
let scope = Scope.factory({
foo: {bar: 'bar'}
})
render.evalValue(tpl, scope)
expect(date).to.have.been.calledWith('bar', 'b')
expect(time).to.have.been.calledWith('y', 2)
})
})
})