[英]Proxyquire can't find module
I'm trying to use proxyquire to mock dependency for testing. 我正在尝试使用proxyquire模拟依赖项以进行测试。 But I keep getting this error Cannot find module
但我不断收到此错误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
我有一个src文件,它在assets/js/src/lib
,而测试在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 错误:在以下位置找不到模块“ ../../assets/js/src/lib/Mandrill”
I'm using Grunt and PhantomJs to run the tests 我正在使用Grunt和PhantomJs运行测试
Here's my Browserify in Gruntfile.js 这是我在Gruntfile.js中的Browserify
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"]
},
}
},
尝试将plugin: ['proxyquireify/plugin']
到specs.options
对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.