debian-mirror-gitlab/spec/frontend/ide/lib/common/disposable_spec.js

45 lines
899 B
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import Disposable from '~/ide/lib/common/disposable';
describe('Multi-file editor library disposable class', () => {
let instance;
let disposableClass;
beforeEach(() => {
instance = new Disposable();
disposableClass = {
2019-07-31 22:56:46 +05:30
dispose: jest.fn().mockName('dispose'),
2018-05-09 12:01:36 +05:30
};
});
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);
});
});
});