diff --git a/src/core/text/Text.js b/src/core/text/Text.js index d68d177..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -744,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/src/core/text/Text.js b/src/core/text/Text.js index d68d177..18fb723 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -744,7 +744,7 @@ set text(text) // eslint-disable-line require-jsdoc { - text = String(text || ' '); + text = String(text === '' || text === null || text === undefined ? ' ' : text); if (this._text === text) { diff --git a/test/core/Text.js b/test/core/Text.js index b8ce561..5799ad4 100644 --- a/test/core/Text.js +++ b/test/core/Text.js @@ -112,4 +112,42 @@ expect(text.width).to.equal(300); }); }); + + describe('text', function () + { + it('should convert numbers into strings', function () + { + const text = new PIXI.Text(2); + + expect(text.text).to.equal('2'); + }); + + it('should not change 0 to \'\'', function () + { + const text = new PIXI.Text(0); + + expect(text.text).to.equal('0'); + }); + + it('should prevent setting null', function () + { + const text = new PIXI.Text(null); + + expect(text.text).to.equal(' '); + }); + + it('should prevent setting undefined', function () + { + const text = new PIXI.Text(); + + expect(text.text).to.equal(' '); + }); + + it('should prevent setting \'\'', function () + { + const text = new PIXI.Text(''); + + expect(text.text).to.equal(' '); + }); + }); });