[英]Convert response body blob to json or plain text in javascript
In my cypress test, I have submitted a request and in the response the body returned as blob
. 在我的柏树测试中,我提交了一个请求,在响应中,尸体以
blob
返回。 How can I check the some text
content in body. 如何检查
some text
中的some text
内容。 Is there any way convert the blob
into json or plain text
. 有什么办法可以将
blob
转换为json or plain text
。 Please see the screenshot attached. 请参阅所附的屏幕截图。 Adding the test code below
在下面添加测试代码
cy.request('https://someurlHere).then((response) => {
expect(response.status).to.eq(200) // this is loooking good
expect(response).to.have.property('headers') // this is loooking good
console.log(response.text());
//var alertArr = [];
//alertArr = response.json();
//console.log(alertArr);
})
Just check for response.body. 只需检查response.body。 See below example.
请参见以下示例。
cy .request('POST', 'http://localhost:8888/users/admin', { name: 'Jane' }) .then((response) => { // response.body is automatically serialized into JSON expect(response.body).to.have.property('name', 'Jane') // true })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.