Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export {
export { default as buildWaiter, _resetWaiterNames } from './build-waiter.ts';
export { default as waitForPromise } from './wait-for-promise.ts';
export { default as waitFor } from './wait-for.ts';
export { waitForFetch } from './wait-for-fetch.ts';
27 changes: 27 additions & 0 deletions addon/src/wait-for-fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { default as waitForPromise } from './wait-for-promise';

export async function waitForFetch(fetchPromise: ReturnType<typeof fetch>) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
waitForPromise(fetchPromise);

const response = await fetchPromise;

return new Proxy(response, {
get(target, prop, receiver) {
const original = Reflect.get(target, prop, receiver);

if (
typeof prop === 'string' &&
['json', 'text', 'arrayBuffer', 'blob', 'formData'].includes(prop)
) {
return (...args: unknown[]) => {
const parsePromise = original.call(target, ...args);

return waitForPromise(parsePromise);
};
}

return original;
},
});
}