In my post, I explained how to test server side REST APIs in Node.js using Mocha, Sinon and Chai. I used ES6 test methods for this and Babel is used to execute it. As test methods are executed at development end, so NO need to transpile ES6 to ES5 first and then debug the converted files. You can directly debug ES6 code with Babel.
In my last post, I spent some hours to create a stub to skip passport.authenticate method for REST API testing. So, I decided to write a separate post on the same. Before we get started, let’s take a look on how auth middleware is implemented:
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).
Symbiosis Centre for Distance Learning (SCDL) is a centre of excellence, offering quality Distance Education. In this post, you will get some tips to prepare exam in short time.
1. Create an effective timetable: First decide how many subjects are to be prepared and how many chapters are in the subject. Make plan and create timetable. Give 1 or 2 days rest after each week.