私はテストを実行すると、save()メソッドでエラーが発生し続けます。ここmochaとmongooseを使うべきですか?
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();
});
});
})
})
})
はエラーです:
$ 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)
我々はuser.should.have 'でユーザ名プロパティを取得するように、我々は実際の関数から' username'プロパティを設定するにはどうすればよいです。プロパティ( 'username'、 'User1'); '?実際にres.send({username: 'User1'}) 'や' res.render( 'home'、{username: 'User1'}) 'として送信できますか? –