Tests for #add(), #update(), #set() and #remove() with an object.
This commit is contained in:
parent
5e0c4d7b7a
commit
b70e0e3e2b
@ -24,7 +24,7 @@ describe('Collection', function () {
|
|||||||
|
|
||||||
this.col.add('foo', true)
|
this.col.add('foo', true)
|
||||||
|
|
||||||
expect(this.col.get('foo')).to.equal(true)
|
expect(this.col.get('foo')).to.be.true()
|
||||||
|
|
||||||
// No sync events.
|
// No sync events.
|
||||||
sinon.assert.notCalled(spy)
|
sinon.assert.notCalled(spy)
|
||||||
@ -32,13 +32,21 @@ describe('Collection', function () {
|
|||||||
// Async event.
|
// Async event.
|
||||||
return eventToPromise(this.col, 'add').then(function (added) {
|
return eventToPromise(this.col, 'add').then(function (added) {
|
||||||
expect(added).to.have.all.keys('foo')
|
expect(added).to.have.all.keys('foo')
|
||||||
expect(added.foo).to.equal(true)
|
expect(added.foo).to.be.true()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an exception if the item already exists', function () {
|
it('throws an exception if the item already exists', function () {
|
||||||
expect(() => this.col.add('bar', true)).to.throw(DuplicateEntry)
|
expect(() => this.col.add('bar', true)).to.throw(DuplicateEntry)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('accepts an object with an id property', function () {
|
||||||
|
const foo = { id: 'foo' }
|
||||||
|
|
||||||
|
this.col.add(foo)
|
||||||
|
|
||||||
|
expect(this.col.get(foo.id)).to.equal(foo)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#update()', function () {
|
describe('#update()', function () {
|
||||||
@ -64,6 +72,14 @@ describe('Collection', function () {
|
|||||||
it('throws an exception if the item does not exist', function () {
|
it('throws an exception if the item does not exist', function () {
|
||||||
expect(() => this.col.update('baz', true)).to.throw(NoSuchEntry)
|
expect(() => this.col.update('baz', true)).to.throw(NoSuchEntry)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('accepts an object with an id property', function () {
|
||||||
|
const bar = { id: 'bar' }
|
||||||
|
|
||||||
|
this.col.update(bar)
|
||||||
|
|
||||||
|
expect(this.col.get(bar.id)).to.equal(bar)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#remove()', function () {
|
describe('#remove()', function () {
|
||||||
@ -88,6 +104,14 @@ describe('Collection', function () {
|
|||||||
it('throws an exception if the item does not exist', function () {
|
it('throws an exception if the item does not exist', function () {
|
||||||
expect(() => this.col.remove('baz', true)).to.throw(NoSuchEntry)
|
expect(() => this.col.remove('baz', true)).to.throw(NoSuchEntry)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('accepts an object with an id property', function () {
|
||||||
|
const bar = { id: 'bar' }
|
||||||
|
|
||||||
|
this.col.remove(bar)
|
||||||
|
|
||||||
|
expect(this.col.has(bar.id)).to.be.false()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#set()', function () {
|
describe('#set()', function () {
|
||||||
@ -97,7 +121,7 @@ describe('Collection', function () {
|
|||||||
|
|
||||||
this.col.set('foo', true)
|
this.col.set('foo', true)
|
||||||
|
|
||||||
expect(this.col.get('foo')).to.equal(true)
|
expect(this.col.get('foo')).to.be.true()
|
||||||
|
|
||||||
// No sync events.
|
// No sync events.
|
||||||
sinon.assert.notCalled(spy)
|
sinon.assert.notCalled(spy)
|
||||||
@ -105,7 +129,7 @@ describe('Collection', function () {
|
|||||||
// Async events.
|
// Async events.
|
||||||
return eventToPromise(this.col, 'add').then(function (added) {
|
return eventToPromise(this.col, 'add').then(function (added) {
|
||||||
expect(added).to.have.all.keys('foo')
|
expect(added).to.have.all.keys('foo')
|
||||||
expect(added.foo).to.equal(true)
|
expect(added.foo).to.be.true()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -126,6 +150,14 @@ describe('Collection', function () {
|
|||||||
expect(updated.bar).to.equal(1)
|
expect(updated.bar).to.equal(1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('accepts an object with an id property', function () {
|
||||||
|
const foo = { id: 'foo' }
|
||||||
|
|
||||||
|
this.col.set(foo)
|
||||||
|
|
||||||
|
expect(this.col.get(foo.id)).to.equal(foo)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user