hook_spec.js 1.98 KB
Newer Older
Luke "Jared" Bennett's avatar
Luke "Jared" Bennett committed
1 2 3 4 5 6 7 8 9 10 11
import Hook from '~/droplab/hook';

describe('Hook', function () {
  describe('class constructor', function () {
    beforeEach(function () {
      this.trigger = { id: 'id' };
      this.list = {};
      this.plugins = {};
      this.config = {};
      this.dropdown = {};

12
      this.dropdownConstructor = spyOnDependency(Hook, 'DropDown').and.returnValue(this.dropdown);
Luke "Jared" Bennett's avatar
Luke "Jared" Bennett committed
13 14 15 16 17 18 19 20 21 22 23 24 25

      this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
    });

    it('should set .trigger', function () {
      expect(this.hook.trigger).toBe(this.trigger);
    });

    it('should set .list', function () {
      expect(this.hook.list).toBe(this.dropdown);
    });

    it('should call DropDown constructor', function () {
26
      expect(this.dropdownConstructor).toHaveBeenCalledWith(this.list, this.config);
Luke "Jared" Bennett's avatar
Luke "Jared" Bennett committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    });

    it('should set .type', function () {
      expect(this.hook.type).toBe('Hook');
    });

    it('should set .event', function () {
      expect(this.hook.event).toBe('click');
    });

    it('should set .plugins', function () {
      expect(this.hook.plugins).toBe(this.plugins);
    });

    it('should set .config', function () {
      expect(this.hook.config).toBe(this.config);
    });

    it('should set .id', function () {
      expect(this.hook.id).toBe(this.trigger.id);
    });

    describe('if config argument is undefined', function () {
      beforeEach(function () {
        this.config = undefined;

        this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
      });

      it('should set .config to an empty object', function () {
        expect(this.hook.config).toEqual({});
      });
    });

    describe('if plugins argument is undefined', function () {
      beforeEach(function () {
        this.plugins = undefined;

        this.hook = new Hook(this.trigger, this.list, this.plugins, this.config);
      });

      it('should set .plugins to an empty array', function () {
        expect(this.hook.plugins).toEqual([]);
      });
    });
  });
});