2014-10-20 71 views
1

我对nodejs和sailsjs框架比较陌生,我非常喜欢用它编写代码,但是来自PHP背景,我发现测试nodeJs有点奇怪。使用Mocha/Sinon测试NodeJs - 风帆

我试图用mochasinon方法loginAuthService的测试,但不得专家,我需要对你如何实现它成功的测试为例,不幸的是在线文档仍然是一个有点可怜的示例将会非常有用,谢谢!

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); 
      }); 
     }); 
    } 

如果你可以让灯亮,这将是非常赞赏

回答

1

检查we.js你如何设置测试例如:

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

集成和单元测试supertest检查:https://github.com/wejs/we/tree/emberjsDev/tests

+1

哇,这资源是相当不错的,非常感谢!还有其他什么?我真的想正确测试我的Js ServerSide代码。 – Fabrizio 2014-10-21 10:24:19

+0

我需要在使用sails.js 0.10.x资源的新结构we.js中更新我的代码...所以我已经准备好了部分serverside ...但是您可以获取我发送的链接并使您测试... – 2014-10-22 04:28:12