2020-03-13 15:44:24 +05:30
|
|
|
import $ from 'jquery';
|
2021-03-08 18:12:59 +05:30
|
|
|
import ClassSpecHelper from 'helpers/class_spec_helper';
|
2020-03-13 15:44:24 +05:30
|
|
|
import VersionCheckImage from '~/version_check_image';
|
|
|
|
|
|
|
|
describe('VersionCheckImage', () => {
|
|
|
|
let testContext;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
testContext = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('bindErrorEvent', () => {
|
|
|
|
ClassSpecHelper.itShouldBeAStaticMethod(VersionCheckImage, 'bindErrorEvent');
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
testContext.imageElement = $('<div></div>');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registers an error event', () => {
|
|
|
|
jest.spyOn($.prototype, 'on').mockImplementation(() => {});
|
|
|
|
// eslint-disable-next-line func-names
|
2021-03-08 18:12:59 +05:30
|
|
|
jest.spyOn($.prototype, 'off').mockImplementation(function () {
|
2020-03-13 15:44:24 +05:30
|
|
|
return this;
|
|
|
|
});
|
|
|
|
|
|
|
|
VersionCheckImage.bindErrorEvent(testContext.imageElement);
|
|
|
|
|
|
|
|
expect($.prototype.off).toHaveBeenCalledWith('error');
|
|
|
|
expect($.prototype.on).toHaveBeenCalledWith('error', expect.any(Function));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the imageElement on error', () => {
|
|
|
|
jest.spyOn($.prototype, 'hide').mockImplementation(() => {});
|
|
|
|
|
|
|
|
VersionCheckImage.bindErrorEvent(testContext.imageElement);
|
|
|
|
|
|
|
|
testContext.imageElement.trigger('error');
|
|
|
|
|
|
|
|
expect($.prototype.hide).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|