Skip to content

Commit 254a965

Browse files
committed
fix: add safety guards to makeBackground for Jest tests
- Guard borderContainer operations to prevent undefined crashes - Guard borderContainer.addChild in boundary creation functions - Allows tests to run without full CreateJS stage initialization - Maintains normal app behavior when stage is available
1 parent 86d394c commit 254a965

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

js/turtles.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,9 @@ Turtles.TurtlesView = class {
862862
const borderContainer = this.borderContainer;
863863

864864
// Remove any old background containers
865-
borderContainer.removeAllChildren();
865+
if (borderContainer) {
866+
borderContainer.removeAllChildren();
867+
}
866868

867869
const turtlesStage = this.stage;
868870
// We put the buttons on the stage so they will be on top
@@ -1216,7 +1218,9 @@ Turtles.TurtlesView = class {
12161218
this._collapsedBoundary = new createjs.Bitmap(img);
12171219
this._collapsedBoundary.x = 0;
12181220
this._collapsedBoundary.y = 55 + LEADING;
1219-
borderContainer.addChild(this._collapsedBoundary);
1221+
if (borderContainer) {
1222+
borderContainer.addChild(this._collapsedBoundary);
1223+
}
12201224
this._collapsedBoundary.visible = false;
12211225
};
12221226

@@ -1255,7 +1259,9 @@ Turtles.TurtlesView = class {
12551259
this._expandedBoundary = new createjs.Bitmap(img);
12561260
this._expandedBoundary.x = 0;
12571261
this._expandedBoundary.y = 55 + LEADING;
1258-
borderContainer.addChild(this._expandedBoundary);
1262+
if (borderContainer) {
1263+
borderContainer.addChild(this._expandedBoundary);
1264+
}
12591265
__makeBoundary2();
12601266
};
12611267

0 commit comments

Comments
 (0)