cy-api icon indicating copy to clipboard operation
cy-api copied to clipboard

2.1.2 version- errors with the body format. The cause is in the highlight.js file

Open OlgaShchekina opened this issue 2 years ago • 5 comments

When the body looks like this : { "forwardTo": " " } , Cypress cy.api returns an error. It works fine with the cy.request and with the previous cy.api version.

Screen Shot 2022-03-07 at 3 14 35 PM Screen Shot 2022-03-08 at 9 43 29 AM

OlgaShchekina avatar Mar 08 '22 17:03 OlgaShchekina

I have added a test for this but did not see a problem, can you add a test showing the crash?

bahmutov avatar Mar 08 '22 19:03 bahmutov

Thanks Gleb ! I will take a look on hightlight lib

LeJeanbono avatar Mar 11 '22 18:03 LeJeanbono

Can you help us to reproduce @OlgaShchekina ?

LeJeanbono avatar Mar 20 '22 13:03 LeJeanbono

Can you help us to reproduce @OlgaShchekina ?

try running this, should be reachable from anywhere, no tokens

 
  it('works with cy.request, fails with cy.api', () => {
    cy.api({
      url: 'https://api-dev.helloextend.com/claims-assistant/contact',
      method: 'POST',
      body: {
        name: 'cypress test',
        phoneNumber: '123-456-7890',
        email: `[email protected]`,
        requestType: 'productProtection',
        locale: 'en-US',
        message: 'This is a cypress test',
      },
      retryOnStatusCodeFailure: true,
    })
      .its('status')
      .should('equal', 200)
  })

muratkeremozcan avatar Jun 29 '23 19:06 muratkeremozcan

I'm experiencing a similar issue. My endpoint is returning a no-content 204, with an empty JSON body. As a quick fix, it seems if I just set the body to an empty object when it is undefined on this line, then it passes.

jmad8 avatar Apr 02 '24 21:04 jmad8