Welcome to mirror list, hosted at ThFree Co, Russian Federation.

version_check_image_spec.js « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ab157105a1d0ce5e18b8df23bf9046ae7ecdd6f (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
36
37
38
39
40
41
42
import $ from 'jquery';
import VersionCheckImage from '~/version_check_image';
import ClassSpecHelper from './helpers/class_spec_helper';

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
      jest.spyOn($.prototype, 'off').mockImplementation(function() {
        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();
    });
  });
});