BigW Consortium Gitlab

disposable_spec.js 898 Bytes
Newer Older
1
import Disposable from '~/ide/lib/common/disposable';
Phil Hughes committed
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 43 44

describe('Multi-file editor library disposable class', () => {
  let instance;
  let disposableClass;

  beforeEach(() => {
    instance = new Disposable();

    disposableClass = {
      dispose: jasmine.createSpy('dispose'),
    };
  });

  afterEach(() => {
    instance.dispose();
  });

  describe('add', () => {
    it('adds disposable classes', () => {
      instance.add(disposableClass);

      expect(instance.disposers.size).toBe(1);
    });
  });

  describe('dispose', () => {
    beforeEach(() => {
      instance.add(disposableClass);
    });

    it('calls dispose on all cached disposers', () => {
      instance.dispose();

      expect(disposableClass.dispose).toHaveBeenCalled();
    });

    it('clears cached disposers', () => {
      instance.dispose();

      expect(instance.disposers.size).toBe(0);
    });
  });
});