mercredi 29 avril 2015

Proxyquire can't find module

I'm trying to use proxyquire to mock dependency for testing. But I keep getting this error Cannot find module

I tried with full path and it's still complaining.

I have a src file which is in assets/js/src/lib and the test in js-tests/specs

Here's the code.

var proxyquire = require('proxyquireify')(require);
var stubs = { 
  'mandrill': { 
      Mandrill: function () { 
          return {
              messages : jasmine.createSpy('send')
          };
      }
  }
};

var jQuery = require('jquery'),
    Mandrill = proxyquire('../../assets/js/src/lib/Mandrill', stubs),
    globalMandrill = require('mandrill');

which I'm getting this error.

Error: Cannot find module '../../assets/js/src/lib/Mandrill' at

I'm using Grunt and PhantomJs to run the tests

Here's my Browserify in Gruntfile.js

browserify : {
    options: {
        preBundleCB: function(b) {
            b.plugin(remapify, [
                   // some module config

            ]);

        }
    },
    dist: {
        files : {
            // some files
        },
        options: {
            transform: ['browserify-shim']
        }
    },
    specs : {
        src : ['js-tests/specs/**/*.js'],
        dest : 'js-tests/build/specs.js',
        options: {
            transform: ["browserify-shim"]
        },
    }

},

Aucun commentaire:

Enregistrer un commentaire