I wanna do a TDD. However, I am going to write test on my controller function for my sails.js project
/*---------------------
:: Gamble
-> controller
---------------------*/
var GambleController = {
index: function(req, res) {
res.send('Hello World!');
}
};
module.exports = GambleController;
However , how can i write a test to test index function that output Hello world? Any one can give a example? Thanks
You could use superagent, there are some example usages, here's one
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();
});
});
// ...
It should be pretty simple to stub out the result object:
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();
};
});
});
});