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