0
        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;


在运行测试时,我遇到了错误。

错误:expect(received).toEqual(expected) // 深度相等

预期:200 收到:401

我收到此错误。我究竟做错了什么 ?

提前致谢。

4

0 回答 0