0

I using chai.should(); for writing node js test case. I am calling REST API and getting the response

{
  "statuscode": 200,
  "message": "success",
  "data": {
    "getEducationDetails": [
      {
        "end_date": "1996-04-31",
        "degree_name": "BE",
        "degree_date": "1993-06-18",
        "location": "Hyderabad",
        "university_name": "Hyderabad",
        "institute_name": "VIT",
        "start_date": "1992-01-01"
      }
    ]
  }
}

I want to test the statuscode in the response is 200 or not and proprieties like location etc.

I have tried

res.body.should.have.property('data')
                    .which.is.an('object')
                    .and.has.property('getEducationDetails')
                    .which.is.an('array')
                    .and.has.property('location')
    .and.has.property('location')

and for stauscode

res.body.should.have.property('stauscode').eql(200)

how can I test these properties?

Thank You in Advance

1 Answers1

0

https://www.npmjs.com/package/chai-things

It will check for all object in array should contain end_date . You can do for all properties

res.body.data.getEducationDetails.should.all.have.property('end_date')
Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75