用Mocha / Sinon – SailstestingNodeJs

我对nodejs和sailsjs框架相对比较陌生,我真的很喜欢用它编写代码,但是来自PHP背景,我发现testingnodeJs有点奇怪。

我试图用mochasinon方法login我的AuthService ,但不是专家,我需要一个例子,你如何实现一个成功的testing,不幸的是,在线文档还是有点差,一个例子将是一个很多有用的感谢!

 login: function(username,password,callback) { User.findOneByUsername(username, function(err,user){ // If has some error if (err) { return callback(err) } // if the user is not found with that username if (!user) { return callback(err,false); } // if is found we match the password bcrypt.compare(password, user.password, function (err, res) { if (!res || err) return callback(err,false); return callback(err,true,user); }); }); } 

如果你能在这个灯光会真的很感激

检查we.js示例以了解如何设置testing:

链接: https : //github.com/wejs/we-example/tree/master/test (现在只有“无头浏览器”testing)

用supertest检查进行集成和unit testing: https : //github.com/wejs/we/tree/emberjsDev/tests