【发布时间】:2019-12-20 22:21:33
【问题描述】:
我是 testcafe 的新手,我在运行 SPA 测试时尝试使用 RequestMock 模拟服务器,不幸的是,每次我运行测试并检查对登录页面的网络请求时,我都会收到 222 响应代码,所以我不确定我做错了什么。
尝试使用 requestHooks 将模拟变量添加到测试中,但也没有成功
import { Selector, RequestMock } from "testcafe";
const mock = RequestMock()
.onRequestTo("http://web.restaurant.docker/api/login")
.respond(
{
result: true,
name: "Test Restaurant",
data: {
name: "Test User",
api_token:
"SOME_TOKEN",
customer_id: 1
},
pos: { "1": "Caja", "2": "Caja Emergencias" }
},
200,
{
"access-control-allow-credentials": true,
"access-control-allow-origin": "*"
}
);
fixture`Login`.page`../index.html`;
test("I can log in to the app", async t => {
// Realiza el login
await t
.expect(
Selector("form.login-form", {
visibilityCheck: true
}).exists
)
.ok()
.typeText("#login-email", "test@test.com")
.typeText("#login-password", "test")
.click(".login-form button");
// Define un nombre al pos
await t.typeText(".dialog input", "test").click(".dialog button.ok");
// Verifica que estoy en la ventana de seleccionar POS
await t.expect(Selector(".restaurant-name").innerText).eql("Test Restaurant");
});
我希望看到将对象传递给 RequestMock 的 200 响应
【问题讨论】:
标签: testing mocking xmlhttprequest e2e-testing testcafe