lundi 2 mars 2015

How to unit test Sails.js 0.10.8?

How can I test Sails.js with mocha.js?


Currently, my project structure is



project
--api
--assets
--tests
|--services
|--Utils.test.js
|--bootstrap.test.js
|--mocha.opts
....


Usually, I just write test cases in test/bootstrap.test.js and everything is fine. But test/services/Utils.test.js wouldn't tested and I don't know how to test Utils.test.js and bootstrap.test.js at once.


The code inside bootstrap.test.js is



var assert = require('assert');
var Sails = require('sails');

var sails;

describe("test sails", function ()
{
before(function (done)
{
Sails.lift({}, function (err, server)
{
sails = server;
if (err)
{
return done(err);
}
done(err, sails);
});
});

describe("test Utils", function()
{
it('should equal 3', function (done)
{
assert.equal(Utils.add(1, 2),3);

done();
});
});

after(function (done)
{
var isDone = false;
sails.lower(function()
{
if (!isDone)
{
done();
isDone = true;
}
});
});
});

Aucun commentaire:

Enregistrer un commentaire