feat: promise support for drops, working on #65

This commit is contained in:
Jun Yang
2019-03-10 18:05:52 +08:00
parent ad0930f152
commit 4a8088d4e4
25 changed files with 260 additions and 250 deletions
+11 -11
View File
@@ -13,34 +13,34 @@ describe('filter', function () {
Filter.clear()
scope = new Scope()
})
it('should create default filter if not registered', function () {
it('should create default filter if not registered', async function () {
const result = new Filter('foo', [], false)
expect(result.name).to.equal('foo')
})
it('should render input if filter not registered', function () {
expect(new Filter('undefined', [], false).render('foo', scope)).to.equal('foo')
it('should render input if filter not registered', async function () {
expect(await new Filter('undefined', [], false).render('foo', scope)).to.equal('foo')
})
it('should call filter impl with corrct arguments', function () {
it('should call filter impl with corrct arguments', async function () {
const spy = sinon.spy()
Filter.register('foo', spy)
new Filter('foo', ['33'], false).render('foo', scope)
await new Filter('foo', ['33'], false).render('foo', scope)
expect(spy).to.have.been.calledWith('foo', 33)
})
it('should render a simple filter', function () {
it('should render a simple filter', async function () {
Filter.register('upcase', x => x.toUpperCase())
expect(new Filter('upcase', [], false).render('foo', scope)).to.equal('FOO')
expect(await new Filter('upcase', [], false).render('foo', scope)).to.equal('FOO')
})
it('should render filters with argument', function () {
it('should render filters with argument', async function () {
Filter.register('add', (a, b) => a + b)
expect(new Filter('add', ['2'], false).render(3, scope)).to.equal(5)
expect(await new Filter('add', ['2'], false).render(3, scope)).to.equal(5)
})
it('should render filters with multiple arguments', function () {
it('should render filters with multiple arguments', async function () {
Filter.register('add', (a, b, c) => a + b + c)
expect(new Filter('add', ['2', '"c"'], false).render(3, scope)).to.equal('5c')
expect(await new Filter('add', ['2', '"c"'], false).render(3, scope)).to.equal('5c')
})
it('should not throw when filter name illegal', function () {
+2 -2
View File
@@ -99,7 +99,7 @@ describe('Value', function () {
})
describe('#value()', function () {
it('should call chained filters correctly', function () {
it('should call chained filters correctly', async function () {
const date = sinon.stub().returns('y')
const time = sinon.spy()
Filter.register('date', date)
@@ -108,7 +108,7 @@ describe('Value', function () {
const scope = new Scope({
foo: { bar: 'bar' }
})
tpl.value(scope)
await tpl.value(scope)
expect(date).to.have.been.calledWith('bar', 'b')
expect(time).to.have.been.calledWith('y', 2)
})