I have creted a sails js application. I want to add unit testing for my application. I am using following approach to do the unit testing. http://sailsjs-documentation.readthedocs.org/en/latest/concepts/Testing/
I am using grunt to test my application with mocha. Now I need a way to override some sails methods (find, update, etc. ) to use for my testing, since I do not want interact with the database when testing the code. Is there a way override sails js methods. As an example when I use User.find method in my testing, I want to have a specific result to test my other methods work perfectly. Any kind of help would be appriciated.
If you want to do testing wihout touching production database, you can use different table/ collection of your database. It's common approach in integration testing (not using a mock).
Here is the example, in file bootstrap.test.js
var Sails = require('sails'),
sails;
before(function (done) {
Sails.lift({
connections: {
mongodbServer: {
database: 'database_test'
}
},
models : {
migrate: 'drop'
}
}, function (err, server) {
sails = server;
if (err) return done(err);
done();
});
});
after(function (done) {
// here you can clear fixtures, etc.
sails.lower(done);
});
It's assumed that your connection use mongodbServer and db database_test. Configure it to meets your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With