mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: break/continue omitting output before them, #123
BREAKING CHANGE: remove default export, now should be used like import
{Liquid} from 'liquidjs'
This commit is contained in:
@@ -2,7 +2,7 @@ import * as chai from 'chai'
|
||||
import * as sinon from 'sinon'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import { Filter } from '../../../../src/template/filter/filter'
|
||||
import Context from '../../../../src/context/context'
|
||||
import { Context } from '../../../../src/context/context'
|
||||
|
||||
chai.use(sinonChai)
|
||||
const expect = chai.expect
|
||||
@@ -14,7 +14,7 @@ describe('filter', function () {
|
||||
ctx = new Context()
|
||||
})
|
||||
it('should create default filter if not registered', async function () {
|
||||
const result = new Filter('foo', [], false)
|
||||
const result = new Filter('foo', [], false) as any
|
||||
expect(result.name).to.equal('foo')
|
||||
})
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import * as chai from 'chai'
|
||||
import Context from '../../../src/context/context'
|
||||
import Output from '../../../src/template/output'
|
||||
import OutputToken from '../../../src/parser/output-token'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Output } from '../../../src/template/output'
|
||||
import { OutputToken } from '../../../src/parser/output-token'
|
||||
import { Filter } from '../../../src/template/filter/filter'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Output', function () {
|
||||
const emitter = { write: (html: string) => (emitter.html += html), html: '' }
|
||||
beforeEach(function () {
|
||||
Filter.clear()
|
||||
emitter.html = ''
|
||||
})
|
||||
|
||||
it('should stringify objects', async function () {
|
||||
@@ -16,25 +18,25 @@ describe('Output', function () {
|
||||
foo: { obj: { arr: ['a', 2] } }
|
||||
})
|
||||
const output = new Output({ value: 'foo' } as OutputToken, false)
|
||||
const html = await output.render(scope)
|
||||
return expect(html).to.equal('[object Object]')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('[object Object]')
|
||||
})
|
||||
it('should skip function property', async function () {
|
||||
const scope = new Context({ obj: { foo: 'foo', bar: (x: any) => x } })
|
||||
const output = new Output({ value: 'obj' } as OutputToken, false)
|
||||
const html = await output.render(scope)
|
||||
return expect(html).to.equal('[object Object]')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('[object Object]')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = new Context({ obj: { toString: () => 'FOO' } })
|
||||
const output = new Output({ value: 'obj' } as OutputToken, false)
|
||||
const str = await output.render(scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
it('should respect to .toString()', async () => {
|
||||
const scope = new Context({ obj: { toString: () => 'FOO' } })
|
||||
const output = new Output({ value: 'obj' } as OutputToken, false)
|
||||
const str = await output.render(scope)
|
||||
return expect(str).to.equal('FOO')
|
||||
await output.render(scope, emitter)
|
||||
return expect(emitter.html).to.equal('FOO')
|
||||
})
|
||||
})
|
||||
|
||||
+14
-10
@@ -1,10 +1,10 @@
|
||||
import * as chai from 'chai'
|
||||
import Tag from '../../../src/template/tag/tag'
|
||||
import Context from '../../../src/context/context'
|
||||
import { Tag } from '../../../src/template/tag/tag'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import * as sinon from 'sinon'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import Liquid from '../../../src/liquid'
|
||||
import TagToken from '../../../src/parser/tag-token'
|
||||
import { Liquid } from '../../../src/liquid'
|
||||
import { TagToken } from '../../../src/parser/tag-token'
|
||||
|
||||
chai.use(sinonChai)
|
||||
const expect = chai.expect
|
||||
@@ -12,6 +12,7 @@ const liquid = new Liquid()
|
||||
|
||||
describe('tag', function () {
|
||||
let ctx: Context
|
||||
const emitter = { write: (html: string) => (emitter.html += html), html: '' }
|
||||
before(function () {
|
||||
ctx = new Context({
|
||||
foo: 'bar',
|
||||
@@ -22,6 +23,9 @@ describe('tag', function () {
|
||||
})
|
||||
Tag.clear()
|
||||
})
|
||||
beforeEach(function () {
|
||||
emitter.html = ''
|
||||
})
|
||||
|
||||
it('should throw when not registered', function () {
|
||||
expect(function () {
|
||||
@@ -51,7 +55,7 @@ describe('tag', function () {
|
||||
value: 'foo',
|
||||
name: 'foo'
|
||||
} as TagToken
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.called
|
||||
})
|
||||
|
||||
@@ -70,29 +74,29 @@ describe('tag', function () {
|
||||
} as TagToken
|
||||
})
|
||||
it('should call tag.render with scope', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch(ctx)
|
||||
})
|
||||
it('should resolve identifier hash', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch({}, {
|
||||
aa: 'bar'
|
||||
})
|
||||
})
|
||||
it('should accept space between key/value', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch({}, {
|
||||
bb: 2
|
||||
})
|
||||
})
|
||||
it('should resolve number value hash', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch(ctx, {
|
||||
cc: 2.3
|
||||
})
|
||||
})
|
||||
it('should resolve property access hash', async function () {
|
||||
await new Tag(token, [], liquid).render(ctx)
|
||||
await new Tag(token, [], liquid).render(ctx, emitter)
|
||||
expect(spy).to.have.been.calledWithMatch(ctx, {
|
||||
dd: 'uoo'
|
||||
})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as chai from 'chai'
|
||||
import * as sinonChai from 'sinon-chai'
|
||||
import * as sinon from 'sinon'
|
||||
import Context from '../../../src/context/context'
|
||||
import { Context } from '../../../src/context/context'
|
||||
import { Filter } from '../../../src/template/filter/filter'
|
||||
import Value from '../../../src/template/value'
|
||||
import { Value } from '../../../src/template/value'
|
||||
|
||||
chai.use(sinonChai)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user