0
我試圖使用supertest
通過一個REST端點返回的響應包含moongose
驗證的驗證錯誤,它看起來像下面如何聲明使用supertest的貓鼬驗證錯誤?
errors: Object {
firstName: Object {
kind: 'required',
message: 'Path `firstName` is required.',
name: 'ValidatorError',
path: 'firstName',
properties: Object {
message: 'Path `{PATH}` is required.',
path: 'firstName',
type: 'required'
},
}
我寫下面的測試
it('should return well formatted error response when first name is missing', function(done){
var user = {lastName:"Ranger", email:"[email protected]"};
request(app)
.post('/api/user')
.send(user)
.end(function(err, res){
res.body.should.have.property("path", "firstName");
done();
});
});
但我驗證收到以下錯誤
AssertionError: expected Object {
errors: Object {
firstName: Object {
kind: 'required',
message: 'Path `firstName` is required.',
name: 'ValidatorError',
path: 'firstName',
properties: Object {
message: 'Path `{PATH}` is required.',
path: 'firstName',
type: 'required'
},
}
},
message: 'User validation failed',
name: 'ValidationError',
} to have property path
at Test.<anonymous> (test/userTests.js:23:25)
at net.js:1276:10
我怎麼能寫這樣的斷言?