curl 如何Assertcypress中cy.请求的响应?

6tdlim6h  于 2023-03-18  发布在  其他
关注(0)|答案(1)|浏览(137)

我想写一个测试来测试响应的主体

it('passes', () => {
    cy.request('POST',"localhost:8080", 
                 {
                   "body":"Hello World", 
                   "header": "Content-Type:application/json"
                 })
         assert that response body HELLO WORLD
              
    
  })

如何Assert响应体?I curl下面的命令将传递响应体

curl -H "Content-Type:application/json" localhost:8080 -d "Hello World"
HELLO WORLD%
euoag5mw

euoag5mw1#

文档中有一些示例,例如

cy.request('POST',"localhost:8080", {...})
  .its('body').should('include', 'HELLO WORLD%')

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

相关问题