37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type {Mock} from 'bun:test';
|
|
import {mock, describe, it, beforeAll, beforeEach, expect} from 'bun:test';
|
|
import {Disposable, DisposableList} from '../../src/disposables';
|
|
|
|
describe(`When using a DisposableList`, () => {
|
|
let disposableList: DisposableList;
|
|
|
|
beforeEach(() => {
|
|
disposableList = new DisposableList();
|
|
});
|
|
|
|
describe(`Given a disposbale list with multiple disposables`, () => {
|
|
let mocks: Array<Mock<any>>;
|
|
let mockDisposables: Disposable[];
|
|
|
|
beforeEach(() => {
|
|
mocks = [mock(() => {}), mock(() => {}), mock(() => {}), mock(() => {})];
|
|
mockDisposables = mocks.map(mock => new Disposable(mock));
|
|
mockDisposables.forEach(mockDisposable => disposableList.add(mockDisposable));
|
|
});
|
|
|
|
describe(`Given the disposable list is disposed`, () => {
|
|
beforeEach(() => {
|
|
disposableList.dispose();
|
|
});
|
|
|
|
it(`disposes all of the disposables in the list`, () => {
|
|
mocks.forEach(mock => expect(mock).toHaveBeenCalled());
|
|
});
|
|
|
|
it(`marks the disposable as disposed`, () => {
|
|
mockDisposables.forEach(disposable => expect(disposable.isDisposed).toBeTrue());
|
|
});
|
|
});
|
|
});
|
|
});
|