Skip to content

Commit

Permalink
added tests for signals emitting when component is added/removed; fix…
Browse files Browse the repository at this point in the history
…ed bug with components being removed from entity not emitting signal
  • Loading branch information
alexdmiller committed Jun 15, 2014
1 parent 373717b commit 43d8f10
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/family.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ var Family = module.exports = Class.extend({
for (i = 0, len = names.length; i < len; ++i) {
if (names[i] === componentName) {
this._entities.remove(entity);
this.entityRemoved.emit(entity);
}
}
},
Expand Down
37 changes: 37 additions & 0 deletions test/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,43 @@ describe('world', function () {
bListener.calledOnce.should.be.false;
});

it('should emit signal when entity has component added', function() {
var world = new CES.World();

var abListener = sinon.spy();
var bListener = sinon.spy();
world.entityAdded('a', 'b').add(abListener);

var entity = new CES.Entity();
entity.addComponent(new CompA());
world.addEntity(entity);

abListener.calledOnce.should.be.false;

entity.addComponent(new CompB());

abListener.calledOnce.should.be.true;
});

it('should emit signal when entity has component removed', function() {
var world = new CES.World();

var abListener = sinon.spy();
var bListener = sinon.spy();
world.entityRemoved('a', 'b').add(abListener);

var entity = new CES.Entity();
entity.addComponent(new CompA());
entity.addComponent(new CompB());
world.addEntity(entity);

abListener.calledOnce.should.be.false;

entity.removeComponent('b');

abListener.calledOnce.should.be.true;
});

describe('with system', function() {
it('addToWorld should be called when system is added', function() {
var world = new CES.World();
Expand Down

0 comments on commit 43d8f10

Please sign in to comment.