【发布时间】:2012-10-30 12:14:44
【问题描述】:
我在运行测试时在 save() 方法中不断收到错误。
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 : 'user1@example.com'
, 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)
【问题讨论】:
-
我们如何从实际函数中设置
username属性,以便我们在user.should.have.property('username', 'User1');中获取用户名属性?我们可以在实际功能中以res.send({username: 'User1'})或res.render('home', {username: 'User1'})发送吗?
标签: unit-testing node.js mongoose mocha.js