1 import { jest } from '@jest/globals';
3 function handleResponse(response: Response) {
4 return response.text().then((text) => {
5 const data = text && JSON.parse(text);
8 const error = (data && data.message) || response.statusText;
9 return Promise.reject(error);
16 export const mockApiWithServer = jest.fn((config: any) => {
17 const url = new URL(`http://localhost/${config.url}`);
20 url.search = new URLSearchParams(config.params).toString();
23 return fetch(url.toString(), {
24 method: config.method,