Skip to content

l3lackcurtains/nodejs-mocha-chai-test-tdd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS Test

Build Status Coverage Status Scrutinizer Code Quality Known Vulnerabilities

Test steps:

  • Unit Tests
  • Integration Tests
  • End to End

Unit Testing Node.js Applications

The core idea with unit testing is to test a function when giving it certain set of inputs. We cann a function with certain parameters and check we got the correct result or not.

It is good practice with Javascript code to have a directory called test/ in our project's root directory.

The Anatomy of unit Test:

Each unit test has the following Structure

  • Test Setup
  • Calling the tested method
  • Asserting

For unit test modules in Nodejs

  • test runner: mocha, alternatively tape
  • assertion library: chai, alternatively the assert module (for asserting)
  • test spies, stubs and mocks: sinon (for test setup).

References for Mocha Chai