You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
I am trying to mock a dependency in a route module in an express js server but cannot get it to work.
I tried everything with the route module loaded in the main server/index.js file so I thought ok just remount the route on another root path so to have two paths to the routes with different prefixes like when you version an end point but this one will be for testing with the mocked service/business layer module which is called ecourier.controller in my sample. See below but even then on the new /apitest route path it still does not mock the Module.... AWWWWWW..
I am trying to mock a dependency in a route module in an express js server but cannot get it to work.
I tried everything with the route module loaded in the main server/index.js file so I thought ok just remount the route on another root path so to have two paths to the routes with different prefixes like when you version an end point but this one will be for testing with the mocked service/business layer module which is called ecourier.controller in my sample. See below but even then on the new /apitest route path it still does not mock the Module.... AWWWWWW..
Please what am I doing wrong...
import chai from 'chai';
import server from '..';
var mock = require('mock-require');
chai.use(require('chai-http'));
var expect = chai.expect;
var route = '/apitest/shipmentDispatched';
var mockreq = null;
var winstoncls = {
stream: {
write: (msg) => { console.log(msg); }
}
}
const emptycls = { name: 'Dummy class' };
mock('../controllers/ecourier.controller', {
updateDispatch: function(res,req,config) {
res.json({ status: 'OK' });
}
});
mock.reRequire('../controllers/ecourier.controller');
import routes from '../routes';
server.use('/apitest', routes({ emptycls, emptycls, emptycls, winstoncls }));
The text was updated successfully, but these errors were encountered: