// Step 1: Install the testing framework (e.g., Mocha) and assertion library (e.g., Chai) as development dependencies
npm install mocha chai --save-dev
// Step 2: Create a test script file, e.g., test.js, in your project directory
// Step 3: Write test cases using Mocha and Chai syntax in test.js
const assert = require('chai').assert;
// Sample function to be tested
function addNumbers(a, b) {
return a + b;
}
// Test case
describe('addNumbers function', () => {
it('should return the sum of two numbers', () => {
// Arrange
const num1 = 2;
const num2 = 3;
// Act
const result = addNumbers(num1, num2);
// Assert
assert.equal(result, 5);
});
it('should handle negative numbers', () => {
// Arrange
const num1 = -2;
const num2 = 3;
// Act
const result = addNumbers(num1, num2);
// Assert
assert.equal(result, 1);
});
// Add more test cases as needed
});
// Step 4: Add a "test" script to your package.json file to run the tests
"scripts": {
"test": "mocha test.js"
}
// Step 5: Run the tests using the following command in the terminal
npm test