简体   繁体   中英

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 . 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);
        })

在此处输入图片说明

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 }) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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