Skip to content

Commit

Permalink
Merge pull request #1 from IanVS/conditional-abort-controller
Browse files Browse the repository at this point in the history
Only test AbortController if defined
  • Loading branch information
IanVS authored Mar 11, 2022
2 parents 4737d13 + 255accd commit 72397f9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,23 @@ describe('Mocking aborts', () => {
});

it('throws when passed an already aborted abort signal in the request init', () => {
const c = new AbortController();
c.abort();
expect(() => fetch('/', { signal: c.signal })).toThrow(expect.any(DOMException));
if (typeof AbortController !== 'undefined') {
const c = new AbortController();
c.abort();
expect(() => fetch('/', { signal: c.signal })).toThrow(expect.any(DOMException));
}
});

it('rejects when aborted before resolved', async () => {
const c = new AbortController();
fetch.mockResponse(async () => {
vi.advanceTimersByTime(60);
return '';
});
setTimeout(() => c.abort(), 50);
await expect(fetch('/', { signal: c.signal })).rejects.toThrow(expect.any(DOMException));
if (typeof AbortController !== 'undefined') {
const c = new AbortController();
fetch.mockResponse(async () => {
vi.advanceTimersByTime(60);
return '';
});
setTimeout(() => c.abort(), 50);
await expect(fetch('/', { signal: c.signal })).rejects.toThrow(expect.any(DOMException));
}
});
});

Expand Down

0 comments on commit 72397f9

Please sign in to comment.