Skahrz Skahrz - 1 month ago 12
Node.js Question

Proxyquire and functions import

I m trying to use proxyquire to simulate an express behaviour and I m having some trouble dealing with the following command :

expressProxy = () => {
return {
use: () => true,
post: () => true,
listen: () => true

Application = proxyquire('./../app', {
'express': expressProxy,
'passport': passportProxy,
'./app/business/service/StrategyFactory': StrategyFactoryProxy

When I start my application using the following code :


I m always having the full express behaviour, as it should normally work.

I m having the full and complete express object just as if it hasn't been redefined...

I m a bit lost and I dont understand what's going on here.

Any information to help me understand ?


By default proxyquire passes all method calls through to the original dependency. You can turn it off using '@noCallThru' if you want to disable it for specific stubs:

var foo = proxyquire('./foo', {
  path: {
      extname: function (file) { ... }
    , '@noCallThru': true

or .noCallThru() if you want to turn it off for all stubs:

// all stubs resolved by proxyquireStrict will not call through by default
var proxyquireStrict = require('proxyquire').noCallThru();

See for a full explanation