【问题标题】:RequestMock returns 222 status code with no bodyRequestMock 返回没有正文的 222 状态码
【发布时间】: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


    【解决方案1】:

    您需要将 RequestMock 附加到您的测试或夹具,如下所述:Attaching Hooks to Tests and Fixtures

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-19
      • 2019-07-15
      • 1970-01-01
      • 2020-01-18
      • 2016-07-11
      • 1970-01-01
      • 2019-12-24
      • 2021-12-08
      相关资源
      最近更新 更多