Dec 18, 2017

Node.js: REST API Testing using Mocha, Sinon and Chai

In my recent post, I covered how to implement token based authentication using Passport, JWT and bcrypt. Let’s extend this post and look into testing REST APIs or server side methods in Node.js using Mocha, Chai and Sinon.

Mocha: It is a test runner to execute our tests.
keywords in code = Describe, It, before, after…etc

Chai: It is an assertion library and allows to write code like writing regular english.
keywords in code = should, assert..etc.

Sinon: It provides test spies (fake functions to track executions), stubs (replace functions with our fake implementation) and mocks (predefined fake method with behaviour).