Test and fix #clear().

This commit is contained in:
Julien Fontanet 2015-04-13 14:53:25 +02:00
parent e072ff2d77
commit 34ac4b25af
2 changed files with 14 additions and 1 deletions

View File

@ -226,7 +226,7 @@ export default class Collection extends EventEmitter {
}
clear () {
forEach(this._items, key => {
forEach(this._items, (_, key) => {
delete this._items[key]
this._size--
this._touch('remove', key)

View File

@ -195,6 +195,19 @@ describe('Collection', function () {
})
})
describe('clear()', function () {
it('removes all items from the collection', function () {
this.col.clear()
expect(this.col.size).to.equal(0)
return eventToPromise(this.col, 'remove').then((items) => {
expect(items).to.have.all.keys('bar')
expect(items.bar).to.not.exist()
})
})
})
describe('deduplicates events', function () {
forEach({
'add & update → add': [