42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import type {Mock} from 'bun:test';
|
|
import {mock, describe, it, beforeEach, expect} from 'bun:test';
|
|
import {Disposable} from '../../src/disposables';
|
|
|
|
describe(`When using a Disposable`, () => {
|
|
describe(`Given a Disposable`, () => {
|
|
let mockFunction: Mock<any>;
|
|
let disposable: Disposable;
|
|
|
|
beforeEach(() => {
|
|
mockFunction = mock(() => {});
|
|
disposable = new Disposable(mockFunction);
|
|
});
|
|
|
|
describe(`Given the disposable is disposed`, () => {
|
|
beforeEach(() => {
|
|
disposable.dispose();
|
|
});
|
|
|
|
it(`executes the disposble`, () => {
|
|
expect(mockFunction).toHaveBeenCalled();
|
|
});
|
|
|
|
it(`marks the disposbale disposed`, () => {
|
|
expect(disposable.isDisposed).toBeTrue();
|
|
});
|
|
|
|
describe(`Given the disposable is repeatedly disposed`, () => {
|
|
beforeEach(() => {
|
|
for (let count = 0; count < 10; count++) {
|
|
disposable.dispose();
|
|
}
|
|
});
|
|
|
|
it(`disposes the disposable only once`, () => {
|
|
expect(mockFunction).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|