How to test controllers in a REST applications

by Anshul Sahni   Last Updated June 20, 2018 20:05 PM

I'm writing a REST api backend in NODE js, which is based on MVC approach. My api routes directly hit the controllers, which in turn import models which are a wrapper around the methods from a library (DB ORM) called sequelize.

What will be the better approach for writing the unit tests for the controllers,

  1. To include models, with mock DB data, in unit tests of the respective controllers
  2. To somehow mock the models and then unit test my controllers without involving the real models at all.

If the second approach is better how will I achieve writing these types of Unit tests

Related Questions

What is the best method for testing a web app?

Updated November 23, 2018 13:05 PM

In c# how do people make complex functions

Updated October 05, 2016 09:02 AM


Updated February 18, 2017 10:05 AM