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

编程入门 行业动态 更新时间:2024-10-11 15:14:05
本文介绍了将响应主体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('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', '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或纯文本

本文发布于:2023-10-12 04:33:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   主体   文本   Blob   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!