Skip to content

Commit 72397f9

Browse files
authored
Merge pull request #1 from IanVS/conditional-abort-controller
Only test AbortController if defined
2 parents 4737d13 + 255accd commit 72397f9

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tests/api.test.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,23 @@ describe('Mocking aborts', () => {
119119
});
120120

121121
it('throws when passed an already aborted abort signal in the request init', () => {
122-
const c = new AbortController();
123-
c.abort();
124-
expect(() => fetch('/', { signal: c.signal })).toThrow(expect.any(DOMException));
122+
if (typeof AbortController !== 'undefined') {
123+
const c = new AbortController();
124+
c.abort();
125+
expect(() => fetch('/', { signal: c.signal })).toThrow(expect.any(DOMException));
126+
}
125127
});
126128

127129
it('rejects when aborted before resolved', async () => {
128-
const c = new AbortController();
129-
fetch.mockResponse(async () => {
130-
vi.advanceTimersByTime(60);
131-
return '';
132-
});
133-
setTimeout(() => c.abort(), 50);
134-
await expect(fetch('/', { signal: c.signal })).rejects.toThrow(expect.any(DOMException));
130+
if (typeof AbortController !== 'undefined') {
131+
const c = new AbortController();
132+
fetch.mockResponse(async () => {
133+
vi.advanceTimersByTime(60);
134+
return '';
135+
});
136+
setTimeout(() => c.abort(), 50);
137+
await expect(fetch('/', { signal: c.signal })).rejects.toThrow(expect.any(DOMException));
138+
}
135139
});
136140
});
137141

0 commit comments

Comments
 (0)