Reputation: 1117
I want to write a test that test the body of response
it('passes', () => {
cy.request('POST',"localhost:8080",
{
"body":"Hello World",
"header": "Content-Type:application/json"
})
assert that response body HELLO WORLD
})
How do I assert the response body? I curl following command will deliver response body
curl -H "Content-Type:application/json" localhost:8080 -d "Hello World"
HELLO WORLD%
Upvotes: 0
Views: 1871
Reputation: 172
There's some examples in the documentation, for example
cy.request('POST',"localhost:8080", {...})
.its('body').should('include', 'HELLO WORLD%')
An live example for @jjhelguero
cy.request({
method: 'POST',
url: 'https://jsonplaceholder.typicode.com/posts',
body: "Hello World",
header: "Content-Type:application/json"
})
.its('body')
.should('have.property', 'id', 101)
Upvotes: 4