【发布时间】:2021-04-09 19:33:12
【问题描述】:
基于赛普拉斯docs,我想在第一次加载夹具后修改响应中的一个字段并保持其他所有内容不变。我知道我可以用 2 个灯具轻松做到这一点,但我不想为了简单的字段更改而复制它。我尝试了以下代码的变体,但没有成功。有什么想法吗?
it('Should have the correct values in monthly', () => {
cy.intercept('POST', `**/full`, (req) => {
req.continue(res => {
res.body.data.monthly = 5000;
res.send(res);
})
});
cy.fixture('calculator/monthlyRepayment.json').as('fixtures:monthlyRepayment');
cy.route('POST', `**/full`, '@fixtures:monthlyRepayment').as(`request:fullData`);
cy.get('[data-test="calculator:monthlyRepayment"]').should('contain', '$5000.00');
})
【问题讨论】:
-
在你的例子中,你不是只存根一条路线吗?如果是这样,您能否修改您的
@fixtures:monthlyRepayment以返回您想要的data.monthly值? -
另外,你为什么使用
cy.intercept和cy.route?cy.route是 deprecated,从 Cypress@6.0.0 开始。
标签: response cypress interceptor