我想断言我的response.body 是否不包含某些提供的值。假设身体有 10 个物体。所有对象都有“id”字段。如何在请求响应上使用某种each或forEach?我知道我可以使用例如
expect(response.body[0].requestId).not.eq(value);
expect(response.body[1].requestId).not.eq(value);
expect(response.body[2].requestId).not.eq(value);
expect(response.body[3].requestId).not.eq(value);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何以更优化的方式对其进行编码。
我用以下方法准备了数组:
const bodyObjects = [
'body[0]',
'body[1]',
'body[2]',
'body[3]',
'body[4]',
];
Run Code Online (Sandbox Code Playgroud)
我的代码
it.only("Something "A" should not see something "B"", () => {
const bodyObjects = [
'body[0]',
'body[1]',
'body[2]',
'body[3]',
'body[4]',
];
cy.request({
method: "POST",
url: Cypress.env("URL",
auth: {
bearer: token,
},
body: {
id: someId,
},
}).then((response, $bodyObjects) => {
responseId = response.body.id;
expect(response.status).to.eq(201);
**MY POTENTIAL ASSERTION**
})
});
Run Code Online (Sandbox Code Playgroud)