【问题标题】:same api, but different response in cypress相同的 api,但在 cypress 中的响应不同
【发布时间】:2023-01-09 22:28:13
【问题描述】:

cypress 版本 6 可以处理相同的 api,但响应不同吗? 如果是,以下是否正确? 如果我们不能,cypress 版本 9 会支持这个吗?

// * same api for each test, but diff response
const api = '/v1/test';

it('test 1', () => {
    cy.intercept(api, {res: '1'});
    // do stuff
});

it('test 2', () => {
    cy.intercept(api, {res: '2'});
    // do stuff
});

it('test 3', () => {
    cy.intercept(api, {res: '2'});
    // do stuff
});

有一些hacking,但正在寻找合适的方法。

【问题讨论】:

    标签: reactjs testing cypress


    【解决方案1】:

    From the cy.intercept() page,

    每次测试前都会自动清除所有拦截。

    因此,如果您在每次测试的基础上设置拦截(在 it() 块中),那么这应该会按您预期的那样工作,每个测试对同一端点都有不同的响应。据我所知,这是 cy.intercept() 自引入以来的行为,并且应该与 Cypress 6 一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-11
      • 2014-09-10
      • 1970-01-01
      • 2021-03-28
      • 2019-07-29
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多