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:
@@ -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', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user