Skip to content

miottto/mocha-unit-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mocha Unit Testing - Node.js

This repository demonstrates my studies on unit tests in Node.js using the Mocha framework and the built-in assert module.

⚙️ How It Works

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.

📌 Technologies Used

  • Node.js - JavaScript runtime environment
  • Mocha - Testing framework
  • Assert - Built-in Node.js assertion module

📂 Project Structure

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

🚀 How to Set Up the Project

1️⃣ Clone the Repository

git clone https://github.com/miottto/mocha-unit-testing.git
cd mocha-unit-testing

2️⃣ Install Dependencies

npm install --global mocha

3️⃣ Edit Scripts Session In package.json file

"scripts": {
  "test": "mocha"
}

4️⃣ Run the Tests

npm test

📜 Example Implementation (index.js)

function add(a, b) {
    return a + b;
}
module.exports = add;

✅ Example Test (test/index-test.js)

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);
    });
});

📖 References

🏆 Contribution

Feel free to contribute with improvements! Open an issue or submit a pull request. 🚀


📌 Author: miottto

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published