Cypress:想部分模拟XHR响应吗
我正在使用Cypress,我想将XHR响应部分存根。我想捕获原始JSON,并对其进行部分编辑 例如:Cypress:想部分模拟XHR响应吗,cypress,stubbing,cypress-cucumber-preprocessor,Cypress,Stubbing,Cypress Cucumber Preprocessor,我正在使用Cypress,我想将XHR响应部分存根。我想捕获原始JSON,并对其进行部分编辑 例如: cy.route('GET','**/subjects','fixture:mySubjects.json') 通过这种方式,我将整个响应截短,但我希望看到: 原始XHR响应(当然还有许多其他属性): 我想要存根的只是名称,并且想要得到: { 'id': 12345, "subjects": [ { "key": "mat
cy.route('GET','**/subjects','fixture:mySubjects.json')代码>
通过这种方式,我将整个响应截短,但我希望看到:
原始XHR响应(当然还有许多其他属性):
我想要存根的只是名称,并且想要得到:
{
'id': 12345,
"subjects": [
{
"key": "mat",
"name": "maths",
"hasAccess": true,
}
],
}
简而言之,我想做的是从响应中删除第二个主题“eng”。非常感谢您的任何想法。请看一看
我不太明白您想要返回或存根的真正响应的哪一部分,但这是这样做的机制
cy.intercept('/integrations', (req) => {
// req.reply() with a callback will send the request to the destination server
req.reply((res) => {
// 'res' represents the real destination response
// you can manipulate 'res' before it's sent to the browser
})
})
如果您使用的是Cypress版本<6,则可以尝试使用具有相同语法的cy.route2()
。是的,我使用的是V5.6.0。我也会尝试发布结果。谢谢我想做的是从回复中删除第二个主题“eng”。我发现了这一点。应用您的解决方案。再次感谢。其他人的发布链接:
cy.intercept('/integrations', (req) => {
// req.reply() with a callback will send the request to the destination server
req.reply((res) => {
// 'res' represents the real destination response
// you can manipulate 'res' before it's sent to the browser
})
})