这是我在服务器上发布的对象
let targetTestObjectToPost = {
name : {
name : "something",
middle : "something",
last : "something"
},
date_of_birth : new Date(1994,12,2),
date_of_join : new Date(2004,3,25),
mail : {
value : "something@gmail.com",
sub : "mobile"
},
phone_num :{
value : "9832983298",
sub : "personal"
},
address : {
address : "something",
street : "abc street",
po_box : "abc po box",
neighborhood : "something",
zipcode : 192923,
city : "city",
state : "state",
nation : "nation",
},
work_profile : {},
};
我从服务器收到此对象
let targetReceiedObject = {
__v: 0,
date_of_birth: '1995-01-01T18:30:00.000Z',
image: 'oaeelstctlxopxeihoo5',
userid: '59fb5d435fd23c7b4cf64be5',
_id: '59fb5d495fd23c7b4cf64be6',
address:
{ address: 'something',
street: 'abc street',
po_box: 'abc po box',
neighborhood: 'something',
zipcode: 192923,
city: 'city',
state: 'state',
nation: 'nation' },
phone_num: { value: 9832983298, sub: 'personal' },
mail: { value: 'something@gmail.com', sub: 'mobile' },
date_of_join: '2004-04-24T18:30:00.000Z',
name: { name: 'something', middle: 'something', last: 'something' } } }
}
当我在服务器上进行测试时,测试块看起来像这样
it('it should post employee successfully',(done)=>{
chai.request(server)
.post('/api/employee')
.set('token',token)
.send(passObject)
.end((err,res)=>{
if(err)
done(err);
else
{
res.should.have.status(200);
let obj = res.body.data;
expect(obj.name).to.eql(passObject.name);
expect(new Date(obj.date_of_birth)).to.equalDate(passObject.date_of_birth);
expect(new Date(obj.date_of_join)).to.equalDate(passObject.date_of_join);
expect(obj.address).to.eql(passObject.address);
expect(obj.work_profile).to.equal(passObject.work_profile);
done();
}
});
});
*它给我测试错误*
Uncaught AssertionError: expected { Object (address, street, ...) } to deeply equal { Object (address, street, ...) }
+ expected - actual
"neighborhood": "somethinfg"
"po_box": "abc po box"
"state": "state"
"street": "abc street"
- "zipcode": 192923
+ "zipcode": "192923"
}
at chai.request.post.set.send.end (test/employee_test.js:159:48)
at Test.Request.callback (node_modules/superagent/lib/node/index.js:619:12)
at node_modules/superagent/lib/node/index.js:795:18
at IncomingMessage.<anonymous> (node_modules/superagent/lib/node/parsers/json.js:16:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
服务器是node.js和express.js, 数据库是mongoose。
架构看起来像这样
name : {
name : { type : String , require : true },
middle : { type : String , require : false },
last : { type : String , require : true },
family_name : { type : String , require : false },
suffix : { type : String , require : false }
},
date_of_birth : { type : Date },
date_of_join : { type : Date , default : Date.now },
mail : {
value : { type : String , require : true } ,
sub : { type : String }
},
phone_num : {
value : { type : Number , require : true },
sub : { type : String }
},
address : {
address : { type : String },
street : { type : String },
po_box : { type : String },
neighborhood : { type : String },
zipcode : { type : Number },
city : { type : String },
state : { type : String },
nation : { type : String }
},
work_profile : { type : ObjectId , ref : 'work_profile' },
image : { type : String , require : true },
userid : { type : ObjectId , ref : 'User' , require : true
**我正在使用chai-http测试服务器。响应采用json格式“**