fix: tests
This commit is contained in:
parent
ac0b951ef0
commit
cecea48996
|
@ -1,4 +1,5 @@
|
|||
import {resource} from '@avocado/resource';
|
||||
import {Trait} from '@avocado/traits';
|
||||
import {Latus} from '@latus/core';
|
||||
import {expect} from 'chai';
|
||||
|
||||
|
@ -48,8 +49,48 @@ describe('Existent', () => {
|
|||
entity.on('destroyed', resolve);
|
||||
}),
|
||||
]);
|
||||
entity.destroy();
|
||||
await entity.destroy();
|
||||
expect(entity.traits).to.deep.equal({});
|
||||
return promise;
|
||||
});
|
||||
it('can be destroyed with deference', async () => {
|
||||
const DELAY = 30;
|
||||
class Waiter extends Trait {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.duration = DELAY / 1000;
|
||||
}
|
||||
|
||||
hooks() {
|
||||
return {
|
||||
|
||||
destroy: () => (elapsed) => {
|
||||
this.duration -= elapsed;
|
||||
return this.duration <= 0;
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
latus.get('%traits.fromType')['Waiter'] = Waiter;
|
||||
await entity.addTrait('Waiter');
|
||||
const promise = Promise.all([
|
||||
new Promise((resolve) => {
|
||||
entity.on('destroying', resolve);
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
entity.on('destroyed', resolve);
|
||||
}),
|
||||
]);
|
||||
let start = Date.now();
|
||||
const handle = setInterval(() => {
|
||||
entity.tick(0.01);
|
||||
}, 10);
|
||||
await entity.destroy();
|
||||
clearInterval(handle);
|
||||
expect(Date.now() - start).to.be.at.least(DELAY * 0.9);
|
||||
return promise;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -90,7 +90,7 @@ describe('Spawner', () => {
|
|||
});
|
||||
}
|
||||
expect(Object.keys(list.entities)).to.have.lengthOf(COUNT + 1);
|
||||
entity.killAllChildren();
|
||||
await entity.killAllChildren();
|
||||
expect(Object.keys(list.entities)).to.have.lengthOf(1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import {assert, expect} from 'chai';
|
||||
import merge from 'deepmerge';
|
||||
import {validate} from 'uuid';
|
||||
|
||||
import {Image} from '../src/resources/image';
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import {assert, expect} from 'chai';
|
||||
import merge from 'deepmerge';
|
||||
import {validate} from 'uuid';
|
||||
|
||||
import Resource from '../src/resource';
|
||||
|
@ -71,7 +70,7 @@ describe('JsonResource', () => {
|
|||
});
|
||||
it("can load to instance", async () => {
|
||||
const resource = new JsonResourceSubclass();
|
||||
resource.load({foo: 420, bar: 'hoo'});
|
||||
await resource.load({foo: 420, bar: 'hoo'});
|
||||
expect(resource.json.foo).to.equal(420);
|
||||
expect(resource.json.bar).to.equal('hoo');
|
||||
});
|
||||
|
|
|
@ -21,20 +21,20 @@ describe('Layer', () => {
|
|||
});
|
||||
describe('entity list interaction', () => {
|
||||
let entity;
|
||||
let entityList;
|
||||
let layer;
|
||||
beforeEach(async () => {
|
||||
const {fromResourceType: {Entity, EntityList, Layer}} = resource(latus);
|
||||
entity = await Entity.load({
|
||||
traits: {
|
||||
Existent: {},
|
||||
Layered: {},
|
||||
Listed: {},
|
||||
},
|
||||
});
|
||||
entityList = new EntityList();
|
||||
const entityList = new EntityList();
|
||||
entityList.addEntity(entity);
|
||||
layer = new Layer();
|
||||
await layer.load({entityList});
|
||||
layer.setEntityList(entityList);
|
||||
})
|
||||
it('delegates to entity list', async () => {
|
||||
expect(Object.keys(layer.entities).length).to.equal(1);
|
||||
|
|
Loading…
Reference in New Issue
Block a user