1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +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');
});
it('cancel prevents onSuccess from being called', async () => {
const onSuccess = vi.fn();
it('cancel prevents then callback from being called', async () => {
const onFulfilled = vi.fn();
const { promise, cancel } = cancellablePromise(
new Promise<string>((resolve) => setTimeout(() => resolve('data'), 100)),
);
const chained = promise.then(onFulfilled).catch(() => {});
cancel();
try {
await promise;
}
catch {
// expected
}
await chained;
expect(onSuccess).not.toHaveBeenCalled();
expect(onFulfilled).not.toHaveBeenCalled();
});
it('CancelledError has correct name property', () => {