This repository was archived by the owner on Apr 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
6. Automatic testing
s.mombuleau edited this page Dec 4, 2018
·
2 revisions
Testing your IA is very important. In order to automatically test the modules, the IA project bundles the Mocha framework, a complete test suite.
One command line:
$ tests
It will run the mocha test suite.
If a module contains a test/ folder, it will automatically be tested by the mocha runner.
Testing for expected result using assert
describe('Calculator', function() {
it('Respond with matching records (3x2 = 6)', function(done) {
let resultPromise = Calculator.getData(['3*2'], '', "en_gb", i18n);
resultPromise.then((result) => {
assert.equal(result, 6);
done();
}).catch((error) => {
done(error);
})
});
Note: the done function without parameter corresponds to a success and with a parameter is an error
it('Handling error', function(done) {
let resultPromise = Calculator.getData(['3****2'], '', "en_gb", i18n);
resultPromise.then((result) => {
done('Error should be handled');
}).catch((error) => {
if (error === "Your formula isn't valid") {
done();
} else {
done(error);
}
})
});
Proxyquire dynamically injects your mock inside the module to test. You can inject a mock into a module by requiring the module using proxyquire and passing along the mock to use.
Here's an example for an hypothetical geo_solver which uses an elasticsearch config:
const geoSolver = proxyquire('../geo_solver', {'elasticsearch':elasticMock});
- For a complete Mocha feature list, check mocha's website
- For a complete documentation, check mocha's wiki
- For a complete documentation, check proxyquire's github