Skip to content

Commit cea8a01

Browse files
committed
Update tests
1 parent 73bb1a2 commit cea8a01

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

packages/flame_forge2d/test/forge2d_world_test.dart

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,40 @@ class _TestForge2DWorld extends Forge2DWorld {
88

99
void main() {
1010
testWithFlameGame(
11-
'Bodies are set to awake after remounting the world',
11+
'Bodies are destroyed after world is removed when destroyBodiesOnRemove is '
12+
'true',
1213
(game) async {
1314
final world = _TestForge2DWorld();
1415
game.add(world);
1516
await game.ready();
1617
final bodyDef = BodyDef()..type = BodyType.dynamic;
17-
final body = world.createBody(bodyDef);
18+
final component = BodyComponent(bodyDef: bodyDef);
19+
world.add(component);
1820
await game.ready();
19-
expect(body.isAwake, isTrue);
20-
game.update(100);
21-
expect(body.isAwake, isFalse);
21+
final body = component.body;
2222

2323
world.removeFromParent();
24+
await game.ready();
25+
expect(world.physicsWorld.bodies, isNot(contains(body)));
26+
},
27+
);
28+
29+
testWithFlameGame(
30+
'Bodies are not destroyed after world is removed when '
31+
'destroyBodiesOnRemove is false',
32+
(game) async {
33+
final world = _TestForge2DWorld()..destroyBodiesOnRemove = false;
2434
game.add(world);
2535
await game.ready();
26-
expect(body.isAwake, isTrue);
36+
final bodyDef = BodyDef()..type = BodyType.dynamic;
37+
final component = BodyComponent(bodyDef: bodyDef);
38+
world.add(component);
39+
await game.ready();
40+
final body = component.body;
41+
42+
world.removeFromParent();
43+
await game.ready();
44+
expect(world.physicsWorld.bodies, contains(body));
2745
},
2846
);
2947
}

0 commit comments

Comments
 (0)