I want to use mocha for node.js. The last test framework I used was Rspec from Ruby on Rails so I'm trying to do it in the same way but I get cnfused by the huge framework and all the libraries I could use.
I'm following the official get started but it doesn't explains how organize the tests.
http://visionmedia.github.io/mocha/#installation
Now, I'm reading that I can use the following libraries:
And I know there are more, this is just the list I saw on mocha official website. For what I can understand, it looks like chai is the one to use with mocha, what do you think about that?
And, so far, I never saw anything to help me to decide where write the tests (okay, in /test/, of course) and how organize everything.
I'm also use the great sails.js framework (based on express) and pomelo.js for different projects, I need to use the same kind of tests on both frameworks, so I'm looking for a general architecture and libraries that I can use on both (so, something not specific to sails.js but usable directly from any other framework)
This is how I plan to organize my tests, do you think that's a correct architecture?
The main issue with node is that there are a lot of frameworks, plugins, libraries and I dont know what's the best choice, node.js is really huge with a big community and that's really difficult to have an overview of all the possibilities.
How do you deal with your tests?
I found the blog post Unit Testing Sails.js Applications With Mocha helpful in regards to setting up and organizing tests.
However, because I'm using Sails version 0.10.5, I decided to clean up the Grunt configuration a bit. I added a file named mocha.js
in the tasks/config/
folder with the following code:
module.exports = function(grunt) {
grunt.config.set('mochaTest', {
test: {
options: {
reporter: 'spec'
},
src: ['tests/**/*.spec.js']
}
});
grunt.loadNpmTasks('grunt-mocha-test');
};
I then registered the task by creating a file named test.js
inside of tasks/register
. Inside this file, I added the following code.
module.exports = function (grunt) {
grunt.registerTask('test', [
'mochaTest'
]
);
};
You can then run grunt test
to see the results.
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