From 552d4c60fbd2bd791553e0873b39a32399ddda14 Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Fri, 17 Feb 2023 19:35:42 -0600 Subject: [PATCH] fix: [#2579] Add tests confirming fix --- src/spec/ActorSpec.ts | 15 +++++++++++++++ src/spec/EntitySpec.ts | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/spec/ActorSpec.ts b/src/spec/ActorSpec.ts index 172dd69c1..f81895c20 100644 --- a/src/spec/ActorSpec.ts +++ b/src/spec/ActorSpec.ts @@ -153,6 +153,21 @@ describe('A game actor', () => { expect(actor.graphics.anchor).toEqual(ex.vec(0, 0)); }); + it('will inherit the scene from the parent entity after being added', () => { + const parent = new ex.Actor(); + const child = new ex.Actor(); + + const engine = TestUtils.engine(); + + engine.add(parent); + + expect(parent.scene).toBe(engine.currentScene); + + parent.addChild(child); + + expect(child.scene).toBe(engine.currentScene); + }); + it('should create actor with valid default options', () => { const actor = new ex.Actor(); expect(actor.anchor.toString()).toEqual('(0.5, 0.5)'); diff --git a/src/spec/EntitySpec.ts b/src/spec/EntitySpec.ts index 28954c8f6..4bbc27b2d 100644 --- a/src/spec/EntitySpec.ts +++ b/src/spec/EntitySpec.ts @@ -375,7 +375,21 @@ describe('An entity', () => { expect(e.scene).toBe(null); expect(child.scene).toBe(null); expect(grandchild.scene).toBe(null); + }); + + it('will inherit the scene from the parent entity after being added', () => { + const parent = new ex.Entity([], 'parent'); + const child = new ex.Entity([], 'child'); + + const scene = new ex.Scene(); + scene.add(parent); + + expect(parent.scene).toBe(scene); + + parent.addChild(child); + + expect(child.scene).toBe(scene); }); it('can removeAllChildren correctly', () => {