如何为MVC控制器函数(sails.js)编写简单的茉莉花testing

我想做一个TDD。 但是,我将为我的sails.js项目编写我的控制器函数的testing

/*--------------------- :: Gamble -> controller ---------------------*/ var GambleController = { index: function(req, res) { res.send('Hello World!'); } }; module.exports = GambleController; 

但是,我怎样才能写一个testing来testing输出Hello世界的索引函数呢? 任何人都可以举个例子吗? 谢谢

你可以使用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(); }); }); // ... 

对结果对象进行存档应该非常简单:

 describe('when we get the game controller', function () { it ('should return hello world', function (done) { GameController.index(null, { send: function (message) { assert.equal(message, 'Hello World!'); done(); }; }); }); });