diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index 9a60e1a6..412d81ce 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -398,7 +398,7 @@ __setBgOverlayImage: function(property, image, callback, options) { if (typeof image === 'string') { fabric.util.loadImage(image, function(img) { - this[property] = new fabric.Image(img, options); + img && (this[property] = new fabric.Image(img, options)); callback && callback(img); }, this, options && options.crossOrigin); } diff --git a/test/unit/canvas_static.js b/test/unit/canvas_static.js index a2caec79..986024a6 100644 --- a/test/unit/canvas_static.js +++ b/test/unit/canvas_static.js @@ -1217,6 +1217,18 @@ }); }); + //how to test with an exception? + /*asyncTest('options in setBackgroundImage from invalid URL', function() { + canvas.backgroundImage = null; + canvas.setBackgroundImage(IMG_SRC + '_not_exist', function() { + equal(canvas.backgroundImage, null); + start(); + }, { + left: 50, + originX: 'right' + }); + });*/ + asyncTest('options in setBackgroundImage from image instance', function() { createImageObject(function(imageInstance) { canvas.setBackgroundImage(imageInstance, function() {