Question

I've a "UserService" object that only contains functions like:

  • exports.usersList
  • exports.insertUser
  • exports.registerUser
  • etc...

In the test file I have:

var userController = serviceFactory.getUserService();

Now, I've to assert that userController points to an UserService but if I do:

typeof userController

It returns only object type and not "UserService" as I want. How can I check it trough node.js assertions?

Was it helpful?

Solution

If you defined a class (that is a Function in JS), just try instanceof

// in your user_controller.js file
Function UserController() {
  ...
}
UserController.prototype.userList = function() {
  ...
}
module.exports = UserController

// in another file
var userController = new UserController();
userController instanceof UserController // prints true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top