2017-11-16 3 views
0

私はノードjsテストケースを書くのにchai.should();を使用しています。私は、REST APIを呼び出すと、私は応答してからstatusCodeをテストしたいエラーが発生しました。未知のAssertionError:{data}プロパティがあると予想されました。

{ 
    "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" 
     } 
    ] 
    } 
} 

は200かないとなど場所

のような礼儀は私が

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

を試してみましたとされ、応答を取得していますstauscodeの場合

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

これらのプロパティをテストするにはどうすればよいですか?

はEND_DATEが含まれている必要がありそれは、アレイ内のすべてのオブジェクトをチェックします事前に

答えて

0

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

をありがとうございました。あなたはすべての物件のために行うことができます

res.body.data.getEducationDetails.should.all.have.property('end_date') 
関連する問題