Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ classic: test query results to not be altered #146

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions packages/classic/test/integration/Query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,58 @@ describe('Query Integration Tests', () => {
expect(ents.length).toBe(1);
expect(ents).toBeInstanceOf(Uint32Array);
});

it('should not alter query results when removing entities', () => {
const world = createWorld();
const TestComponent = defineComponent({ value: Types.f32 });

for (let i = 0; i < 10; i += 1) {
const eid = addEntity(world);
addComponent(world, TestComponent, eid);
}

const results = query(world, [TestComponent]);
const length = results.length;
for (const eid of results) {
removeEntity(world, eid);
}

expect(length).toBe(results.length);
});

it('should not alter query results when removing a query component', () => {
const world = createWorld();
const TestComponent = defineComponent({ value: Types.f32 });

for (let i = 0; i < 10; i += 1) {
const eid = addEntity(world);
addComponent(world, TestComponent, eid);
}

const results = query(world, [TestComponent]);
const length = results.length;
for (const eid of results) {
removeComponent(world, TestComponent, eid);
}

expect(length).toBe(results.length);
});

it('should not alter query results when buffered', () => {
const world = enableBufferedQueries(createWorld());
const TestComponent = defineComponent({ value: Types.f32 });

for (let i = 0; i < 10; i += 1) {
const eid = addEntity(world);
addComponent(world, TestComponent, eid);
}

const results = query(world, [TestComponent]);
const length = results.length;
for (const eid of results) {
removeEntity(world, eid);
}

expect(length).toBe(results.length);
});
});