fix: test
This commit is contained in:
parent
ac9e0b4134
commit
9b60744ae2
|
@ -2,27 +2,28 @@ import {expect, test} from 'vitest';
|
||||||
|
|
||||||
import Component from './component.js';
|
import Component from './component.js';
|
||||||
|
|
||||||
test('creates instances', () => {
|
const fakeEcs = {markChange() {}};
|
||||||
|
|
||||||
|
test('creates instances', async () => {
|
||||||
class CreatingComponent extends Component {
|
class CreatingComponent extends Component {
|
||||||
static properties = {
|
static properties = {
|
||||||
foo: {defaultValue: 'bar', type: 'string'},
|
foo: {defaultValue: 'bar', type: 'string'},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const ComponentInstance = new CreatingComponent();
|
const ComponentInstance = new CreatingComponent(fakeEcs);
|
||||||
ComponentInstance.create(1);
|
await ComponentInstance.create(1);
|
||||||
expect(ComponentInstance.get(1).entity)
|
expect(ComponentInstance.get(1).entity)
|
||||||
.to.equal(1);
|
.to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('does not serialize default values', () => {
|
test('does not serialize default values', async () => {
|
||||||
class CreatingComponent extends Component {
|
class CreatingComponent extends Component {
|
||||||
static properties = {
|
static properties = {
|
||||||
foo: {defaultValue: 'bar', type: 'string'}, bar: {type: 'uint8'},
|
foo: {defaultValue: 'bar', type: 'string'}, bar: {type: 'uint8'},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const fakeEcs = {markChange() {}};
|
|
||||||
const ComponentInstance = new CreatingComponent(fakeEcs);
|
const ComponentInstance = new CreatingComponent(fakeEcs);
|
||||||
ComponentInstance.create(1)
|
await ComponentInstance.create(1)
|
||||||
expect(ComponentInstance.get(1).toJSON())
|
expect(ComponentInstance.get(1).toJSON())
|
||||||
.to.deep.equal({});
|
.to.deep.equal({});
|
||||||
ComponentInstance.get(1).bar = 1;
|
ComponentInstance.get(1).bar = 1;
|
||||||
|
@ -30,14 +31,14 @@ test('does not serialize default values', () => {
|
||||||
.to.deep.equal({bar: 1});
|
.to.deep.equal({bar: 1});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('reuses instances', () => {
|
test('reuses instances', async () => {
|
||||||
class ReusingComponent extends Component {
|
class ReusingComponent extends Component {
|
||||||
static properties = {
|
static properties = {
|
||||||
foo: {type: 'string'},
|
foo: {type: 'string'},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const ComponentInstance = new ReusingComponent();
|
const ComponentInstance = new ReusingComponent(fakeEcs);
|
||||||
ComponentInstance.create(1);
|
await ComponentInstance.create(1);
|
||||||
const instance = ComponentInstance.get(1);
|
const instance = ComponentInstance.get(1);
|
||||||
ComponentInstance.destroy(1);
|
ComponentInstance.destroy(1);
|
||||||
expect(ComponentInstance.get(1))
|
expect(ComponentInstance.get(1))
|
||||||
|
@ -46,7 +47,7 @@ test('reuses instances', () => {
|
||||||
ComponentInstance.destroy(1);
|
ComponentInstance.destroy(1);
|
||||||
})
|
})
|
||||||
.to.throw();
|
.to.throw();
|
||||||
ComponentInstance.create(1);
|
await ComponentInstance.create(1);
|
||||||
expect(ComponentInstance.get(1))
|
expect(ComponentInstance.get(1))
|
||||||
.to.equal(instance);
|
.to.equal(instance);
|
||||||
});
|
});
|
||||||
|
|
|
@ -341,10 +341,10 @@ test('applies update patches', async () => {
|
||||||
.to.equal(128);
|
.to.equal(128);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('applies entity deletion patches', () => {
|
test('applies entity deletion patches', async () => {
|
||||||
const ecs = new Ecs({Components: {Position}});
|
const ecs = new Ecs({Components: {Position}});
|
||||||
ecs.createSpecific(16, {Position: {x: 64}});
|
await ecs.createSpecific(16, {Position: {x: 64}});
|
||||||
ecs.apply({16: false});
|
await ecs.apply({16: false});
|
||||||
expect(Array.from(ecs.entities).length)
|
expect(Array.from(ecs.entities).length)
|
||||||
.to.equal(0);
|
.to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user