foundation-testing.timeout
Home > @genesislcap/foundation-testing > timeout
timeout variable
Timeout utility.
Signature:
timeout: (callback: (context: any) => Promise<any>, duration?: number) => (context: any) => Promise<any>
Example 1
A promise that never ends.
test(
'should fail',
timeout(async () => {
await new Promise(() => {});
assert.ok(true);
}, 5_000),
);
Example 2
A slow API.
test(
'should fail',
timeout(async () => {
const slowMockAPI = delayedResolve({ foo: 'bar' }, 4_000);
await slowMockAPI();
assert.unreachable('should have timed out');
}, 2_000),
);