Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
tests: add test checking entity.destroy() removal of components
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPeicho committed Aug 23, 2020
1 parent 7ad68b7 commit 1e7f169
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion test/unit/entitymanager.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from "ava";
import { World } from "../../src";
import { Component, World } from "../../src";

test("entity id", (t) => {
var world = new World();
Expand Down Expand Up @@ -43,3 +43,40 @@ test("deferred entity remove", (t) => {
t.is(world.entityManager.count(), 0);
t.is(world.entityManager.entitiesToRemove.length, 0);
});

test("remove entity clears and reset components first ", (t) => {
class MyComponent extends Component {
constructor() {
super();
this.isReset = false;
}
dispose() {
this.isReset = true;
super.dispose();
}
}
const world = new World();
world.registerComponent(MyComponent, false);

let entity = world.createEntity();
entity.addComponent(MyComponent);

let component = entity.getComponent(MyComponent);
t.is(component.isReset, false);

// Deletes component immeditatly.
entity.remove(true);
t.is(component.isReset, true);

// Deletes component is a deferred manner.

entity = world.createEntity();
entity.addComponent(MyComponent);
component = entity.getComponent(MyComponent);
t.is(component.isReset, false);

entity.remove();
world.entityManager.processDeferredRemoval();
t.is(component.isReset, true);

});

0 comments on commit 1e7f169

Please sign in to comment.