Add tests for listenImage function, fix private variables initialization
This commit is contained in:
@@ -58,9 +58,9 @@ class ImageWrapper extends ImageBase {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<import("./events.js").EventsKey>}
|
||||
* @type {function():void}
|
||||
*/
|
||||
this.imageListenerKeys_ = null;
|
||||
this.unlisten_ = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
|
||||
@@ -46,9 +46,9 @@ class ImageTile extends Tile {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<import("./events.js").EventsKey>}
|
||||
* @type {function():void}
|
||||
*/
|
||||
this.imageListenerKeys_ = null;
|
||||
this.unlisten_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
||||
@@ -53,9 +53,9 @@ class IconImage extends EventTarget {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<import("../events.js").EventsKey>}
|
||||
* @type {function():void}
|
||||
*/
|
||||
this.imageListenerKeys_ = null;
|
||||
this.unlisten_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
|
||||
46
test/spec/ol/image.test.js
Normal file
46
test/spec/ol/image.test.js
Normal file
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user