如何为MVC Controller函数编写简单的jasmine测试(sails.js)

Kit*_* Ho 1 tdd node.js jasmine sails.js

我想做一个TDD.但是,我将在我的sails.js项目的控制器函数上编写测试

/*---------------------
    :: Gamble
    -> controller
---------------------*/
var GambleController = {

  index: function(req, res) {
      res.send('Hello World!');
  }


};
module.exports = GambleController;
Run Code Online (Sandbox Code Playgroud)

但是,如何编写测试来测试输出Hello world的索引函数?任何人都可以举个例子吗?谢谢

Alb*_*gni 5

你可以使用superagent,有一些例子用法,这里是一个

describe('/signout', function() {
  var agent = superagent.agent();
  it('should start with signin', loginUser(agent));
  it('should sign the user out', function(done) {
    agent.get('http://localhost:3000/signout').end(function(err, res) {
      res.should.have.status(200);
      res.redirects.should.eql(['http://localhost:3000/']);
      res.text.should.include('Who are you?');
      return done();
    });
  });
  // ...
Run Code Online (Sandbox Code Playgroud)