Tôi tiếp tục gặp lỗi trong phương thức save() khi chạy thử nghiệm.Tôi nên dùng mocha và mongoose như thế nào?
var User = require('../../models/user')
, should = require('should');
describe('User', function(){
describe('#save()', function(){
it('should save without error', function(done){
var user = new User({
username : 'User1'
, email : '[email protected]'
, password : 'foo'
});
user.save(function(err, user){
if (err) throw err;
it('should have a username', function(done){
user.should.have.property('username', 'User1');
done();
});
});
})
})
})
đây là lỗi:
$ mocha test/unit/user.js
․
✖ 1 of 1 test failed:
1) User #save() should save without error:
Error: timeout of 2000ms exceeded
at Object.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:1
61:14)
at Timer.list.ontimeout (timers.js:101:19)
Làm sao chúng ta có thể thiết lập 'sở hữu username' từ chức năng thực để chúng ta có được sở hữu Tên truy nhập trong 'user.should.have. thuộc tính ('username', 'User1'); '? Chúng ta có thể gửi như 'res.send ({username: 'User1'})' hay 'res.render ('home', {username: 'User1'})' trong hàm thực? –