|
1 | 1 | import { beforeEach, describe, expect, it } from 'vitest';
|
2 |
| -import { createWorld, TraitInstance } from '../src'; |
| 2 | +import { createWorld, relation, TraitInstance } from '../src'; |
3 | 3 | import { trait } from '../src/trait/trait';
|
4 | 4 | import { universe } from '../src/universe/universe';
|
5 | 5 |
|
@@ -27,6 +27,24 @@ describe('World', () => {
|
27 | 27 | expect(world.entities.length).toBe(1);
|
28 | 28 | });
|
29 | 29 |
|
| 30 | + it('reset should remove entities with auto-remove relations', () => { |
| 31 | + const Node = trait(); |
| 32 | + const ChildOf = relation({ autoRemoveTarget: true, exclusive: true }); |
| 33 | + |
| 34 | + const world = createWorld(); |
| 35 | + |
| 36 | + // Create a parent node and a child node. |
| 37 | + const parentNode = world.spawn(Node); |
| 38 | + world.spawn(Node, ChildOf(parentNode)); |
| 39 | + |
| 40 | + // Expect this to not throw, since the ChildOf relation will automatically |
| 41 | + // remove the child node when the parent node is destroyed first. |
| 42 | + expect(() => world.reset()).not.toThrow(); |
| 43 | + |
| 44 | + // Always has one entity that is the world itself. |
| 45 | + expect(world.entities.length).toBe(1); |
| 46 | + }); |
| 47 | + |
30 | 48 | it('errors if more than 16 worlds are created', () => {
|
31 | 49 | for (let i = 0; i < 16; i++) {
|
32 | 50 | createWorld();
|
|
0 commit comments