Skip to content

Instantly share code, notes, and snippets.

Software testing is an integral part of software development and quality assurance. Testing can help us write better and quality code, spot ambiguities early, catch regression, refactor with confidence and also deploy to production while enjoying a cup of coffee .

https://media.giphy.com/media/dGhlifOCTtSdW/giphy.gif

We need to have a structured test with test cases that verify different behaviours of our application. Mocha is a JavaScript framework that organizes our test cases and runs them for us. Although Mocha will not verify our tests behaviours, we are going to make use of Nodejs assert library to verify our test behaviours.

Introduction to NodeJS Module

NodeJS is a runtime environment built on Chrome’s V8 engine that enables us to write and run JavaScript outside a web browser. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run a

// index.js
let counter = 0;
const generateId = () => {/* */};
class StudentManagement {
constructor() {}
add(...students) {
students.forEach((student) => {
// index.js
let counter = 0
const generateId = () => {/* */}
class StudentManagement {
constructor(students) {/* */}
add(student) {
this.#students.push({
$ npm init -y
// index.js
let counter = 0;
const generateId = () => {
counter++;
return counter;
};
class StudentManagement {
#students = []
$ cd students-manager
$ mkdir students-manager
const path = require("path")
const extension = path.extname(process.argv[1])
console.log(extension)
npm test
{
"name": "mocha_assert",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha index.test.js"
},
"keywords": [],
"author": "",