Mocha
lastmod 2022-08-16created 2017-02-1111 edits
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
Troubleshooting
Close Http Server
When testing with Node, if the server does not shut down, you can fix it as follows. in test:
before(async () => {
process.env.PORT = await portfinder.getPortPromise({port: 10002});
app = require('./../../../app');
});
after(async () => {
require('./../../../app').stop();
});
and in app:
...
let port = process.env.PORT || 8080;
let server = app.listen(port, () => {
console.log('App listening on port %s, in environment %s!', port, _.toUpper(process.env.NODE_ENV || ''));
});
function stop() {
server.close();
}
module.exports = server;
module.exports.stop = stop;
See also
Favorite site
- Mocha web site
- JavaScript Test (Mocha + chai + karma)
- TDD libraries - mocha, assert, should, supertest (mocha, supertest)
- node js testing: mocha, expect, supertest (mocha, supertest)
- How To Use Mocha With Node.js For Test-Driven Development to Avoid Pain and Ship Products Faster
- Mocha, the most widely used test framework in NodeJS
Article
- Stackoverflow - JavaScript unit test tools for TDD
- JavaScript Testing Framework Comparison: Jasmine vs Mocha
- JavaScript unit testing with Mocha + Karma
- TDD 1. Mocha - Getting started
- How to test an express application with mocha
Pages that link here