我是否需要测试前端客户端应用程序的实际API调用?

问题描述 投票:0回答:1

我是C#和JavaScript的新手,我正在制作一个ASP.NET / React / Reded应用程序。我使用superagent写了一个简单的HTTP post请求:

import request from "superagent";

export const authenticationService = {
    login
};

function login(email, password) {
    return request.post("http://localhost:55903/api/login/contractor")
                  .type("form")
                  .send({ EmailAddress: email})
                  .send({ Password: password })
                  .then((res) => {
                      return res;
                  })
                  .catch((err) => {
                      return err;
                  });
};

我的主要问题是我需要UNIT TEST实际的登录功能吗?到目前为止,我已经看到了模拟HTTP响应的示例,以测试React / Redux方面的内容,但我还没有看到像上面的HTTP请求函数被测试的示例。

javascript reactjs unit-testing asp.net-web-api
1个回答
0
投票

在您的情况下,在前端端最好模拟数据,因为您没有测试HTTP请求,您正在测试您的React应用程序正在显示正确的事情。

但是,应该测试HTTP请求,但是在后端方面。因此,您的C#代码不应使用React / Redux代码来测试登录请求。

© www.soinside.com 2019 - 2024. All rights reserved.