简体   繁体   English

将响应主体Blob转换为javascript中的json或纯文本

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM