[英]Webstorm IDE and mocha tests using global.expect
I currently run the following command to run my mocha tests: 我目前正在运行以下命令来运行我的摩卡测试:
./node_modules/.bin/mocha --require ./my.js
and in the js file, I am using sinon and expect for SpyOn... 在js文件中,我正在使用sinon并期望使用SpyOn ...
global.expect = require('must');
global.sinon = require('sinon');
How do I configure the Mocha task runner to use this external file. 如何配置Mocha任务运行程序以使用此外部文件。 Using
--require ./my.js
I still see ReferenceError: spyOn is not defined
使用
--require ./my.js
我仍然看到ReferenceError: spyOn is not defined
Any thoughts on this? 有什么想法吗?
Required modules are resolved relative to the working directory specified in "Working directory" field of Mocha Run/Debug configuration. 相对于Mocha Run / Debug配置的“工作目录”字段中指定的工作目录,解析了所需的模块。
Here is the configuration that works for me: 这是适合我的配置:
working directory: C:\WebstormProjects\mocha_sinon
Mocha package: C:\WebstormProjects\mocha_sinon\node_modules\mocha
Extra options: --require ./with_req/util.js
Test directory: C:\WebstormProjects\mocha_sinon\with_req
My spec file: 我的规格文件:
var EventEmitter = require('events').EventEmitter;
var should = require('should');
describe('EventEmitter', function(){
describe('#emit()', function(){
it('should invoke the callback', function(){
var spy = sinon.spy()
, emitter = new EventEmitter;
emitter.on('foo', spy);
emitter.emit('foo');
spy.called.should.equal.true;
})
})
})
util.js; util.js;
global.sinon = require('sinon');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.