summaryrefslogtreecommitdiff
path: root/spec/javascripts/version_check_image_spec.js
blob: 0e69fcc4c5ff65e84dfcaa7fb7ec7d546701758c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import $ from 'jquery';
import VersionCheckImage from '~/version_check_image';
import ClassSpecHelper from './helpers/class_spec_helper';

describe('VersionCheckImage', function() {
  describe('bindErrorEvent', function() {
    ClassSpecHelper.itShouldBeAStaticMethod(VersionCheckImage, 'bindErrorEvent');

    beforeEach(function() {
      this.imageElement = $('<div></div>');
    });

    it('registers an error event', function() {
      spyOn($.prototype, 'on');
      spyOn($.prototype, 'off').and.callFake(function() {
        return this;
      });

      VersionCheckImage.bindErrorEvent(this.imageElement);

      expect($.prototype.off).toHaveBeenCalledWith('error');
      expect($.prototype.on).toHaveBeenCalledWith('error', jasmine.any(Function));
    });

    it('hides the imageElement on error', function() {
      spyOn($.prototype, 'hide');

      VersionCheckImage.bindErrorEvent(this.imageElement);

      this.imageElement.trigger('error');

      expect($.prototype.hide).toHaveBeenCalled();
    });
  });
});