prevent throw error for undefined text

This commit is contained in:
Anton Lavrenov 2016-09-13 14:24:24 -04:00
parent 5bb4994b0e
commit 886bf7c4c5
2 changed files with 15 additions and 1 deletions

View File

@ -150,7 +150,7 @@
context.fillStrokeShape(this);
},
setText: function(text) {
var str = Konva.Util._isString(text) ? text : text.toString();
var str = Konva.Util._isString(text) ? text : (text || '').toString();
this._setAttr(TEXT, str);
return this;
},

View File

@ -13,6 +13,20 @@ suite('Text', function(){
layer.draw();
});
// ======================================================
test('text with undefined text property should not throw an error', function() {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var text = new Konva.Text({text: undefined});
layer.add(text);
layer.draw();
assert.equal(text.getWidth(), 0);
});
test('add text with shadows', function() {
var stage = addStage();
var layer = new Konva.Layer();