断言响应数组中的标头

0 request node.js cypress

我想断言标题在此输入图像描述来自赛普拉斯的响应,但在运行测试时出现错误

错误 ::: assertexpected { Object (content-security-policy, Expect-ct, ...) } 具有属性 text/plain;charset=ISO-8859-1

我尝试过下面的代码

describe("Assert header in response",function(){
    
beforeEach(function(){
    cy.fixture("datainfixturefile").then(function(data){
        this.data= data
        var base=this.data.dcode
    })
})

    it.only('Valid Request',function(){
        cy.request('POST',this.data.BaseURL+this.data.ValidReq).then((response) =>
        {
           expect(response).to.have.property('status',200);
           expect(response.body).contains('APP-');
           expect(response.headers).to.have.property("Content-Type", "text/plain;charset=ISO-8859-1");
        })
    })

Run Code Online (Sandbox Code Playgroud)

小智 5

我认为您想要指定键和值

expect(response).to.have.property('status', 200)
expect(response.headers).to.have.property('content-type', 'text/plain; charset=ISO-8859-1')                       
Run Code Online (Sandbox Code Playgroud)

查看方法属性

.property(名称[, val[, 消息]])

  • @param { 字符串 } 名称
  • @param { 混合 } val (可选)
  • @param { String } 消息可选

断言目标具有给定键名称的属性