examples icon indicating copy to clipboard operation
examples copied to clipboard

NetworkError at XMLHttpRequest.send

Open josuevalrob opened this issue 2 years ago • 0 comments

Test:

describe('When function authApi its passed', () => {
    test("Authentication services", async () => {
        const user: Response<UserInfo> = await request.get('user');
        // expect(userMock?.lastName).toEqual('Valencia');
        expect(user.payload?.lastName).toEqual('Valencia');

    });
})

The feature:

import ky from 'ky';

const api = ky.extend({
    prefixUrl: '/api/',
    retry: 0,
});
export const request: Request = {
    get: async <R>(url: string) => {
        const res: Response<R> = await api.get(url).json();
        return res;
    },
}

Server configuration Screenshot 2022-05-19 at 17 27 17

The error

NetworkError
at XMLHttpRequest.send (/Users/project/ui/.yarn/cache/xhr2-npm-0.2.1/node_modules/xhr2/lib/xhr2.js:281:19)
at /Users/project/ui/.yarn/cache/whatwg-fetch-npm-3.6.2/node_modules/whatwg-fetch/dist/fetch.umd.js:600:11
at new Promise (<anonymous>)
at fetch (/Users/project/ui/.yarn/cache/whatwg-fetch-npm-3.6.2/node_modules/whatwg-fetch/dist/fetch.umd.js:507:12)
at /Users/project/ui/.yarn/cache/ky-npm-0.30.0/node_modules/ky/distribution/utils/time.js:11:10
at new Promise (<anonymous>)
at timeout (/Users/project/ui/.yarn/cache/ky-npm-0.30.0/node_modules/ky/distribution/utils/time.js:3:69)
at Ky._fetch (/Users/project/ui/.yarn/cache/ky-npm-0.30.0/node_modules/ky/distribution/core/Ky.js:213:23)
at async fn (/Users/project/ui/.yarn/cache/ky-npm-0.30.0/node_modules/ky/distribution/core/Ky.js:84:28)
at async Promise.result.<computed> [as json] (/Users/project/ui/.yarn/cache/ky-npm-0.30.0/node_modules/ky/distribution/core/Ky.js:120:39)

Why am i importing XMLHttpRequest library: ReferenceError: XMLHttpRequest is not defined

What could be the issue?

josuevalrob avatar May 19 '22 15:05 josuevalrob