реагируйте шутливо-насмешливый ответ, не возвращающий ожидаемое значение

#reactjs #mocking #ts-jest #jest-fetch-mock

Вопрос:

         const data = JSON.stringify({ statusText: "bar", status: 200 });
        var init = {
            "status": 200, "statusText": "data", "Headers": new Headers({
                Accept: "application/json",
                "Content-Type": "application/json",
            })
        };

        fetchMock.mockResponseOnce(JSON.stringify({ statusText: "bar", status: 200 }), init);
        let apiService = new Api();
        let response = await apiService.get('http://webapidev.agl.com/api/users/whoami', null);
        expect(response).toBeInstanceOf(apiResponse);
        expect(response.httpCode).toEqual(200);

------------------------------------


        let res = await fetch(fullPath,
            {
                mode: 'cors',
                method: 'GET',
                credentials: 'include',
                headers: headers ? headers : new Headers({
                    Accept: "application/json",
                    "Content-Type": "application/json",
                })
            }).then(async (response: Response) => {
                console.log("Reached here");
                if (!response.ok) {
                    serviceResponse.message = response.statusText;
                    serviceResponse.status = apiStatus.Error;
                    serviceResponse.data = [];
                    serviceResponse.httpCode = response.status;
                }
                else {
                    serviceResponse = await buildSuccessResponse(response);
                }
            }, (error) => {
                serviceResponse = buildFailedResponse(error);
            })
            .catch(error => {
                serviceResponse = buildFailedResponse(error);
            });

        console.log("Completed retrieving from : "   fullPath);
        return serviceResponse;


 

Во время выполнения теста я получаю ошибку ниже.

Ошибка: ожидание(получено).toEqual(ожидается) // глубокое равенство

Ожидается: 200 Получено: 401

Я получаю эту ошибку. Что я делаю не так?

Заранее спасибо.