From 1332a07b34ef42b5ca9b624bd0449c5b42d4dfcf Mon Sep 17 00:00:00 2001 From: Erik Onarheim Date: Sat, 27 Jan 2024 15:35:13 -0600 Subject: [PATCH] fix: Empty label constructor (#2904) Fixes an issue where an empty label constructor would crash `new ex.Label()` brought on the discord --- CHANGELOG.md | 1 + src/engine/Label.ts | 2 +- src/spec/LabelSpec.ts | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d555b58e6..97f775ede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -138,6 +138,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed issue where an empty constructor on `new ex.Label()` would crash - Fixed issue where pointer events did not work properly when using [[ScreenElement]]s - Fixed issue where debug draw was not accurate when using *AndFill suffixed [[DisplayMode]]s diff --git a/src/engine/Label.ts b/src/engine/Label.ts index 4d6cc256d..4d23616d5 100644 --- a/src/engine/Label.ts +++ b/src/engine/Label.ts @@ -99,7 +99,7 @@ export class Label extends Actor { */ constructor(options?: LabelOptions & ActorArgs) { super(options); - const {text, pos, x, y, spriteFont, font, color} = options; + const {text, pos, x, y, spriteFont, font, color} = { text: '', ...options }; this.pos = pos ?? (x && y ? vec(x, y) : this.pos); this.text = text ?? this.text; diff --git a/src/spec/LabelSpec.ts b/src/spec/LabelSpec.ts index 491f90cff..d80a18326 100644 --- a/src/spec/LabelSpec.ts +++ b/src/spec/LabelSpec.ts @@ -24,6 +24,12 @@ describe('A label', () => { expect(sut).not.toBeNull(); }); + it('can construct with empty text', () => { + expect(() => { + const sut = new ex.Label(); + }).not.toThrow(); + }); + it('can be constructed with a font', () => { const sut = new ex.Label({ text: 'some text',