This repository demonstrates my studies on unit tests in Node.js using the Mocha framework and the built-in assert module.
In this project, I used a Test-Driven Development to build a method that calculates factorial expressions. I put into practice the assert module and Mocha test framework to drive my development by constructing an automated test suite that is reliable, maintainable and expressive.
- Node.js - JavaScript runtime environment
- Mocha - Testing framework
- Assert - Built-in Node.js assertion module
mocha-unit-testing/
│-- test/
│ └── index-test.js # Unit tests
│-- index.js # Function implementation
│-- package.json # Project configuration
│-- .gitignore # Ignored files for Git
│-- README.md # Project documentation
git clone https://github.com/miottto/mocha-unit-testing.git
cd mocha-unit-testing
npm install --global mocha
"scripts": {
"test": "mocha"
}
npm test
function add(a, b) {
return a + b;
}
module.exports = add;
const assert = require('assert');
const add = require('../index');
describe('Addition Function', function() {
it('should return 5 when adding 2 and 3', function() {
assert.strictEqual(add(2, 3), 5);
});
});
Feel free to contribute with improvements! Open an issue or submit a pull request. 🚀
📌 Author: miottto