Skip to content

Commit 54ae505

Browse files
authored
Merge pull request #146 from pietrovismara/sliced-query-results
✅ classic: test query results to not be altered
2 parents 61f23b0 + a55d336 commit 54ae505

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

packages/classic/test/integration/Query.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,58 @@ describe('Query Integration Tests', () => {
343343
expect(ents.length).toBe(1);
344344
expect(ents).toBeInstanceOf(Uint32Array);
345345
});
346+
347+
it('should not alter query results when removing entities', () => {
348+
const world = createWorld();
349+
const TestComponent = defineComponent({ value: Types.f32 });
350+
351+
for (let i = 0; i < 10; i += 1) {
352+
const eid = addEntity(world);
353+
addComponent(world, TestComponent, eid);
354+
}
355+
356+
const results = query(world, [TestComponent]);
357+
const length = results.length;
358+
for (const eid of results) {
359+
removeEntity(world, eid);
360+
}
361+
362+
expect(length).toBe(results.length);
363+
});
364+
365+
it('should not alter query results when removing a query component', () => {
366+
const world = createWorld();
367+
const TestComponent = defineComponent({ value: Types.f32 });
368+
369+
for (let i = 0; i < 10; i += 1) {
370+
const eid = addEntity(world);
371+
addComponent(world, TestComponent, eid);
372+
}
373+
374+
const results = query(world, [TestComponent]);
375+
const length = results.length;
376+
for (const eid of results) {
377+
removeComponent(world, TestComponent, eid);
378+
}
379+
380+
expect(length).toBe(results.length);
381+
});
382+
383+
it('should not alter query results when buffered', () => {
384+
const world = enableBufferedQueries(createWorld());
385+
const TestComponent = defineComponent({ value: Types.f32 });
386+
387+
for (let i = 0; i < 10; i += 1) {
388+
const eid = addEntity(world);
389+
addComponent(world, TestComponent, eid);
390+
}
391+
392+
const results = query(world, [TestComponent]);
393+
const length = results.length;
394+
for (const eid of results) {
395+
removeEntity(world, eid);
396+
}
397+
398+
expect(length).toBe(results.length);
399+
});
346400
});

0 commit comments

Comments
 (0)