mirror of
https://github.com/mathuo/dockview
synced 2025-08-18 07:06:02 +00:00
chore: add tests
This commit is contained in:
parent
fe8845631d
commit
943ea3b93e
@ -1,4 +1,4 @@
|
|||||||
import { MutableDisposable } from '../lifecycle';
|
import { CompositeDisposable, MutableDisposable } from '../lifecycle';
|
||||||
|
|
||||||
describe('lifecycle', () => {
|
describe('lifecycle', () => {
|
||||||
test('mutable disposable', () => {
|
test('mutable disposable', () => {
|
||||||
@ -23,4 +23,29 @@ describe('lifecycle', () => {
|
|||||||
|
|
||||||
mutableDisposable.dispose();
|
mutableDisposable.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('composite disposable', () => {
|
||||||
|
const d1 = {
|
||||||
|
dispose: jest.fn(),
|
||||||
|
};
|
||||||
|
const d2 = {
|
||||||
|
dispose: jest.fn(),
|
||||||
|
};
|
||||||
|
const d3 = {
|
||||||
|
dispose: jest.fn(),
|
||||||
|
};
|
||||||
|
const d4 = {
|
||||||
|
dispose: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const cut = new CompositeDisposable(d1, d2);
|
||||||
|
cut.addDisposables(d3, d4);
|
||||||
|
|
||||||
|
cut.dispose();
|
||||||
|
|
||||||
|
expect(d1.dispose).toHaveBeenCalledTimes(1);
|
||||||
|
expect(d2.dispose).toHaveBeenCalledTimes(1);
|
||||||
|
expect(d3.dispose).toHaveBeenCalledTimes(1);
|
||||||
|
expect(d4.dispose).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
export function tryParseJSON(
|
|
||||||
text: string,
|
|
||||||
reviver?: (this: any, key: string, value: any) => any
|
|
||||||
): any | undefined;
|
|
||||||
export function tryParseJSON<T>(
|
|
||||||
text: string,
|
|
||||||
reviver?: (this: any, key: string, value: any) => any
|
|
||||||
): T | undefined {
|
|
||||||
try {
|
|
||||||
return JSON.parse(text, reviver) as T;
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('failed to parse JSON');
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ export class CompositeDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public addDisposables(...args: IDisposable[]) {
|
public addDisposables(...args: IDisposable[]) {
|
||||||
args?.forEach((arg) => this.disposables.push(arg));
|
args.forEach((arg) => this.disposables.push(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {
|
public dispose() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user