feat: exported Drop interface for #107

Deprecate snake_cased options and APIs, sed #109
This commit is contained in:
harttle
2019-02-28 00:05:08 +08:00
parent b69c3a3203
commit 7bee9fc92d
26 changed files with 227 additions and 179 deletions
+10
View File
@@ -0,0 +1,10 @@
import { expect } from 'chai'
import { Drop } from '../../../src/drop/drop'
describe('drop/drop', function () {
class CustomDrop extends Drop { }
it('.valueOf() should return undefined by default', async function () {
expect(new CustomDrop().valueOf()).to.be.undefined
})
})
+2 -2
View File
@@ -181,11 +181,11 @@ describe('scope', function () {
expect(scope.get('foo')).to.equal('bar')
})
})
describe('strict_variables', function () {
describe('strictVariables', function () {
let scope: Scope
beforeEach(function () {
scope = new Scope(ctx, {
strict_variables: true
strictVariables: true
} as any)
})
it('should throw when variable not defined', function () {
+5 -12
View File
@@ -25,20 +25,13 @@ describe('Output', function () {
})
const output = new Output({ value: 'foo' } as OutputToken, false)
const html = await output.render(scope)
return expect(html).to.equal('{"obj":{"arr":["a",2]}}')
})
it('should skip circular property', async function () {
const ctx = { foo: { num: 2 }, bar: 'bar' } as any
ctx.foo.circular = ctx
const output = new Output({ value: 'foo' } as OutputToken, false)
const html = await output.render(new Scope(ctx))
return expect(html).equal('{"num":2,"circular":{"bar":"bar"}}')
return expect(html).to.equal('[object Object]')
})
it('should skip function property', async function () {
const scope = new Scope({ 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('{"foo":"foo"}')
return expect(html).to.equal('[object Object]')
})
it('should respect to .toString()', async () => {
const scope = new Scope({ obj: { toString: () => 'FOO' } })
@@ -52,9 +45,9 @@ describe('Output', function () {
const str = await output.render(scope)
return expect(str).to.equal('FOO')
})
it('should respect to .liquid_method_missing()', async () => {
const scope = new Scope({ obj: { liquid_method_missing: (x: string) => x.toUpperCase() } })
const output = new Output({ value: 'obj.foo' } as OutputToken, false)
it('should respect to .toString()', async () => {
const scope = new Scope({ obj: { toString: () => 'FOO' } })
const output = new Output({ value: 'obj' } as OutputToken, false)
const str = await output.render(scope)
return expect(str).to.equal('FOO')
})
-4
View File
@@ -34,10 +34,6 @@ describe('util/underscore', function () {
it('should return "" for undefined', function () {
expect(_.stringify(undefined)).to.equal('')
})
it('should use Object.prototype.toString if no toString method exists', function () {
const obj = { toString: undefined }
expect(_.stringify(obj)).to.equal('[object Object]')
})
it('should return regex string for RegExp', function () {
const reg = /foo/g
expect(_.stringify(reg)).to.equal('/foo/g')