我是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请求函数被测试的示例。
在您的情况下,在前端端最好模拟数据,因为您没有测试HTTP请求,您正在测试您的React应用程序正在显示正确的事情。
但是,应该测试HTTP请求,但是在后端方面。因此,您的C#代码不应使用React / Redux代码来测试登录请求。