/* These utilities help manipulate time by controlling the order of resolution of promises */ export interface IResume { withSuccess: (val: T) => void; withFailure: (reason: any) => void; } export function pauseOn(fn: (...args: any[]) => Promise): PromiseLike> { const mock = fn as jest.Mock; return new Promise((resolve) => { mock.mockImplementationOnce(() => new Promise((success, failure) => { resolve({ withFailure: failure, withSuccess: success }); })); }); } export class LatchedPromise extends Promise { public didFire: boolean = false; } export function latch(p: PromiseLike): LatchedPromise { const ret = new LatchedPromise((resolve, reject) => { p.then((_) => { ret.didFire = true; resolve(_); }, (_) => { ret.didFire = true; reject(_); }); }); return ret; }