Gonzalo Pincheira Arancibia Gonzalo Pincheira Arancibia - 1 year ago 119
Javascript Question

Mocha: Approach to Testing instance of express.Router

I've been designing a javascript controller file and I want to testing if the instance of my controller have a instance of the express's method


import {expect} from 'chai';
import {UF_Controller} from '../../controllers/uf.controller.js';

describe('UF Controller', UFControllerDescription);

function UFControllerDescription(){
it('1. Should be have a express router instance', spec1);

function spec1(){

and my controller

import express from 'express';
import { uf } from '../models/uf.model';

class UFController{

this.router = express.Router();
this.router.get('/', this.getAll);

getAll(req, res, next){

getUF(req, res, next){

insertUF(req, res, next){

replaceUF(req, res, next){

updateUF(req, res, next){

deleteUF(req, res, next){

export const UF_Controller = new UFController();

My question is:
This is a valid way check an instance of the express router???

Answer Source

There's no need to duck-type Express router.

express.Router isn't a constructor an doesn't establish normal prototype chain that can be detected with instanceof. Instead, it establishes prototype chain manually via hacky mixin technique.

It can be tested with

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download