diff --git a/src/ol/Image.js b/src/ol/Image.js index 74c53c29b1..cb2098044a 100644 --- a/src/ol/Image.js +++ b/src/ol/Image.js @@ -58,9 +58,9 @@ class ImageWrapper extends ImageBase { /** * @private - * @type {Array} + * @type {function():void} */ - this.imageListenerKeys_ = null; + this.unlisten_ = null; /** * @protected diff --git a/src/ol/ImageTile.js b/src/ol/ImageTile.js index 0a4989d64a..8d934f7c39 100644 --- a/src/ol/ImageTile.js +++ b/src/ol/ImageTile.js @@ -46,9 +46,9 @@ class ImageTile extends Tile { /** * @private - * @type {Array} + * @type {function():void} */ - this.imageListenerKeys_ = null; + this.unlisten_ = null; /** * @private diff --git a/src/ol/style/IconImage.js b/src/ol/style/IconImage.js index 30a66f430d..940b946f83 100644 --- a/src/ol/style/IconImage.js +++ b/src/ol/style/IconImage.js @@ -53,9 +53,9 @@ class IconImage extends EventTarget { /** * @private - * @type {Array} + * @type {function():void} */ - this.imageListenerKeys_ = null; + this.unlisten_ = null; /** * @private diff --git a/test/spec/ol/image.test.js b/test/spec/ol/image.test.js new file mode 100644 index 0000000000..99798a0610 --- /dev/null +++ b/test/spec/ol/image.test.js @@ -0,0 +1,46 @@ +import {listenImage} from '../../../src/ol/Image.js'; + + +describe('HTML Image loading', function() { + let handleLoad, handleError, img; + + beforeEach(function() { + handleLoad = sinon.spy(); + handleError = sinon.spy(); + img = new Image(); + }); + + it('handles load event', function(done) { + img.src = 'spec/ol/data/dot.png'; + listenImage(img, handleLoad, handleError); + + setTimeout(function() { + expect(handleLoad).to.be.called(); + expect(handleError).not.to.be.called(); + done(); + }, 200); + }); + + it('handles error event', function(done) { + img.src = 'invalid.jpeg'; + listenImage(img, handleLoad, handleError); + + setTimeout(function() { + expect(handleLoad).not.to.be.called(); + expect(handleError).to.be.called(); + done(); + }, 200); + }); + + it('handles cancelation', function(done) { + img.src = 'spec/ol/data/dot.png'; + listenImage(img, handleLoad, handleError)(); + + setTimeout(function() { + expect(handleLoad).not.to.be.called(); + expect(handleError).not.to.be.called(); + done(); + }, 200); + }); + +});