将响应主体Blob转换为javascript中的json或纯文本 [英] Convert response body blob to json or plain text in javascript

查看:556
本文介绍了将响应主体Blob转换为javascript中的json或纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的柏树测试中,我提交了一个请求,并在响应中将正文返回为 blob 。如何检查正文中的一些文本内容。有什么方法可以将 blob 转换为 json或纯文本。请参阅所附的屏幕截图。在下面添加测试代码

In my cypress test, I have submitted a request and in the response the body returned as blob. How can I check the some text content in body. Is there any way convert the blob into 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);
        })

推荐答案

只需检查response.body。请参见以下示例。

Just check for 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
  })

这篇关于将响应主体Blob转换为javascript中的json或纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆