From b70e0e3e2b2ee751c9a7baa43522901ddd42a918 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 8 Apr 2015 11:40:07 +0200 Subject: [PATCH] Tests for #add(), #update(), #set() and #remove() with an object. --- packages/xo-collection/src/index.spec.js | 40 +++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/xo-collection/src/index.spec.js b/packages/xo-collection/src/index.spec.js index 399b90e92..89f5bfb71 100644 --- a/packages/xo-collection/src/index.spec.js +++ b/packages/xo-collection/src/index.spec.js @@ -24,7 +24,7 @@ describe('Collection', function () { this.col.add('foo', true) - expect(this.col.get('foo')).to.equal(true) + expect(this.col.get('foo')).to.be.true() // No sync events. sinon.assert.notCalled(spy) @@ -32,13 +32,21 @@ describe('Collection', function () { // Async event. return eventToPromise(this.col, 'add').then(function (added) { 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 () { 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 () { @@ -64,6 +72,14 @@ describe('Collection', function () { it('throws an exception if the item does not exist', function () { 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 () { @@ -88,6 +104,14 @@ describe('Collection', function () { it('throws an exception if the item does not exist', function () { 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 () { @@ -97,7 +121,7 @@ describe('Collection', function () { this.col.set('foo', true) - expect(this.col.get('foo')).to.equal(true) + expect(this.col.get('foo')).to.be.true() // No sync events. sinon.assert.notCalled(spy) @@ -105,7 +129,7 @@ describe('Collection', function () { // Async events. return eventToPromise(this.col, 'add').then(function (added) { 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) }) }) + + 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) + }) }) })