2014-07-21 170 views
1

單元測試geddy控制器如何?這是我想測試的一個例子。Geddy單元測試控制器

var assert = require('assert') 
    , tests 
    , controller = geddy.controller.create('Users'); 

tests = { 
    'test user controller, add new user': function (next) { 
     var user = User.create({username: 'hbinduni', 
      password: 'MyPassword!', 
      confirmPassword: 'MyPassword!', 
      familyName: 'binduni', 
      givenName: 'binduni', 
      email: '[email protected]'}); 

     //need to unit test controller.add here 
     //how to mock req, resp? 
     controller.add(req, resp, user); 

     assert.equal(out, null); 
     next(); 
    } 

}; 

module.exports = tests; 

我該如何對控制器方法進行單元測試?如何模擬請求和響應?

謝謝。

回答