1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 02:44:45 +00:00

fix(stdlib): improve cancellablePromise test to actually verify then callback is not called

Co-authored-by: robonen <26167508+robonen@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-26 15:01:56 +00:00
parent da17d2d068
commit 6b2707e24a

View File

@@ -37,23 +37,20 @@ describe('cancellablePromise', () => {
await expect(promise).rejects.toThrow('Request aborted'); await expect(promise).rejects.toThrow('Request aborted');
}); });
it('cancel prevents onSuccess from being called', async () => { it('cancel prevents then callback from being called', async () => {
const onSuccess = vi.fn(); const onFulfilled = vi.fn();
const { promise, cancel } = cancellablePromise( const { promise, cancel } = cancellablePromise(
new Promise<string>((resolve) => setTimeout(() => resolve('data'), 100)), new Promise<string>((resolve) => setTimeout(() => resolve('data'), 100)),
); );
const chained = promise.then(onFulfilled).catch(() => {});
cancel(); cancel();
try { await chained;
await promise;
}
catch {
// expected
}
expect(onSuccess).not.toHaveBeenCalled(); expect(onFulfilled).not.toHaveBeenCalled();
}); });
it('CancelledError has correct name property', () => { it('CancelledError has correct name property', () => {