Skip to content

Commit

Permalink
fix: Empty label constructor (#2904)
Browse files Browse the repository at this point in the history
Fixes an issue where an empty label constructor would crash `new ex.Label()` brought on the discord
  • Loading branch information
eonarheim authored Jan 27, 2024
1 parent 8dd4bf7 commit 1332a07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/spec/LabelSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 1332a07

Please sign in to comment.