mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
chore(typescript): ship to TypeScript
This commit is contained in:
+19
-19
@@ -1,12 +1,12 @@
|
||||
import chai from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import sinonChai from 'sinon-chai'
|
||||
import sinon from 'sinon'
|
||||
import Tag from '../../src/tag.js'
|
||||
import { factory as scopeFactory } from '../../src/scope.js'
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import * as sinon from 'sinon'
|
||||
import Tag from '../../src/tag'
|
||||
import Scope from '../../src/scope'
|
||||
import Filter from '../../src/filter'
|
||||
import Render from '../../src/render.js'
|
||||
import parser from '../../src/parser.js'
|
||||
import Render from '../../src/render'
|
||||
import parser from '../../src/parser'
|
||||
|
||||
chai.use(sinonChai)
|
||||
chai.use(chaiAsPromised)
|
||||
@@ -30,21 +30,21 @@ describe('render', function () {
|
||||
})
|
||||
|
||||
it('should render html', function () {
|
||||
const scope = scopeFactory({})
|
||||
const scope = new Scope()
|
||||
return expect(render.renderTemplates([{ type: 'html', value: '<p>' }], scope)).to.eventually.equal('<p>')
|
||||
})
|
||||
})
|
||||
|
||||
describe('.renderValue()', function () {
|
||||
it('should respect to .to_liquid() method', function () {
|
||||
const scope = scopeFactory({
|
||||
const scope = new Scope({
|
||||
bar: { to_liquid: x => 'custom' }
|
||||
})
|
||||
const tpl = Template.parseValue('bar')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('custom')
|
||||
})
|
||||
it('should stringify objects', function () {
|
||||
const scope = scopeFactory({
|
||||
const scope = new Scope({
|
||||
foo: { obj: { arr: ['a', 2] } }
|
||||
})
|
||||
const tpl = Template.parseValue('foo')
|
||||
@@ -54,29 +54,29 @@ describe('render', function () {
|
||||
const ctx = { foo: { num: 2 }, bar: 'bar' }
|
||||
ctx.foo.circular = ctx
|
||||
|
||||
const scope = scopeFactory(ctx)
|
||||
const scope = new Scope(ctx)
|
||||
const tpl = Template.parseValue('foo')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"num":2,"circular":{"bar":"bar"}}')
|
||||
})
|
||||
it('should skip function property', function () {
|
||||
const scope = scopeFactory({ obj: { foo: 'foo', bar: x => x } })
|
||||
const scope = new Scope({ obj: { foo: 'foo', bar: x => x } })
|
||||
const tpl = Template.parseValue('obj')
|
||||
return expect(render.renderValue(tpl, scope)).to.eventually.equal('{"foo":"foo"}')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = scopeFactory({ obj: { toString: () => 'FOO' } })
|
||||
const scope = new Scope({ obj: { toString: () => 'FOO' } })
|
||||
const tpl = Template.parseValue('obj')
|
||||
const str = await render.renderValue(tpl, scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
})
|
||||
it('should respect to .to_s()', async () => {
|
||||
const scope = scopeFactory({ obj: { to_s: () => 'FOO' } })
|
||||
const scope = new Scope({ obj: { to_s: () => 'FOO' } })
|
||||
const tpl = Template.parseValue('obj')
|
||||
const str = await render.renderValue(tpl, scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
})
|
||||
it('should respect to .liquid_method_missing()', async () => {
|
||||
const scope = scopeFactory({ obj: { liquid_method_missing: x => x.toUpperCase() } })
|
||||
const scope = new Scope({ obj: { liquid_method_missing: x => x.toUpperCase() } })
|
||||
const tpl = Template.parseValue('obj.foo')
|
||||
const str = await render.renderValue(tpl, scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
@@ -93,7 +93,7 @@ describe('render', function () {
|
||||
filter.register('date', (l, r) => l + r)
|
||||
filter.register('time', (l, r) => l + 3 * r)
|
||||
const tpl = Template.parseValue('foo.bar[0] | date: "b" | time:2')
|
||||
const scope = scopeFactory({
|
||||
const scope = new Scope({
|
||||
foo: { bar: ['a'] }
|
||||
})
|
||||
expect(render.evalValue(tpl, scope)).to.equal('ab6')
|
||||
@@ -101,7 +101,7 @@ describe('render', function () {
|
||||
it('should reserve type', function () {
|
||||
filter.register('arr', () => [1])
|
||||
const tpl = Template.parseValue('"x" | arr')
|
||||
expect(render.evalValue(tpl, scopeFactory())).to.deep.equal([1])
|
||||
expect(render.evalValue(tpl, new Scope())).to.deep.equal([1])
|
||||
})
|
||||
it('should eval filter with correct arguments', function () {
|
||||
const date = sinon.stub().returns('y')
|
||||
@@ -109,7 +109,7 @@ describe('render', function () {
|
||||
filter.register('date', date)
|
||||
filter.register('time', time)
|
||||
const tpl = Template.parseValue('foo.bar | date: "b" | time:2')
|
||||
const scope = scopeFactory({
|
||||
const scope = new Scope({
|
||||
foo: { bar: 'bar' }
|
||||
})
|
||||
render.evalValue(tpl, scope)
|
||||
|
||||
Reference in New Issue
Block a user