mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Add MutableDisposable tests
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
*/
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { Disposable, MutableDisposable } from 'common/Lifecycle';
|
||||
import { IDisposable } from 'common/Types';
|
||||
|
||||
class TestDisposable extends Disposable {
|
||||
public get isDisposed(): boolean {
|
||||
@@ -43,3 +44,52 @@ describe('Disposable', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('MutableDisposable', () => {
|
||||
const mutable = new MutableDisposable();
|
||||
class TrackedDisposable extends Disposable {
|
||||
public get isDisposed(): boolean { return this._isDisposed; }
|
||||
}
|
||||
describe('value', () => {
|
||||
it('should set the value', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
assert.strictEqual(mutable.value, d1);
|
||||
assert.isFalse(d1.isDisposed);
|
||||
});
|
||||
it('should dispose of any previous value', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
const d2 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.value = d2;
|
||||
assert.strictEqual(mutable.value, d2);
|
||||
assert.isTrue(d1.isDisposed);
|
||||
assert.isFalse(d2.isDisposed);
|
||||
});
|
||||
});
|
||||
describe('clear', () => {
|
||||
it('should clear and dispose of the object', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.clear();
|
||||
assert.strictEqual(mutable.value, undefined);
|
||||
assert.isTrue(d1.isDisposed);
|
||||
});
|
||||
});
|
||||
it('dispose', () => {
|
||||
it('should dispose of the object', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.dispose();
|
||||
assert.strictEqual(mutable.value, undefined);
|
||||
assert.isTrue(d1.isDisposed);
|
||||
});
|
||||
it('should prevent using the MutableDisposable again', () => {
|
||||
const d1 = new TrackedDisposable();
|
||||
mutable.value = d1;
|
||||
mutable.dispose();
|
||||
mutable.value = new TrackedDisposable();
|
||||
assert.strictEqual(mutable.value, undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user