Mocha
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
Node를 테스트로 사용할 경우 서버가 종료되지 않는 현상이 발생될 경우 아래와 같이 해결할 수 있다. 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 라이브러리 - mocha, assert, should, supertest (mocha, supertest)
- node js 테스트 : mocha, expect, supertest (mocha, supertest)
- How To Use Mocha With Node.js For Test-Driven Development to Avoid Pain and Ship Products Faster
- NodeJS에서 가장 많이 사용하는 테스트 프레임웍, Mocha
Article
- Stackoverflow - JavaScript unit test tools for TDD
- JavaScript Testing Framework Comparison: Jasmine vs Mocha
- Mocha + Karma 로 자바스크립트 단위 테스트 하기
- TDD 1. Mocha - Getting started
- mocha를 이용한 express application test 방법
이 문서를 가리키는 문서