Webstorm IDE和mocha使用global.expect进行测试
Webstorm IDE and mocha tests using global.expect
我当前运行以下命令来运行mocha测试:
./node_modules/.bin/mocha --require ./my.js
和在js文件中,我使用sinon,并期望SpyOn…
global.expect = require('must');
global.sinon = require('sinon');
如何配置Mocha任务运行器来使用这个外部文件?使用--require ./my.js
,我仍然看到ReferenceError: spyOn is not defined
对此有什么想法吗?
所需模块相对于Mocha Run/Debug配置的" working directory"字段中指定的工作目录进行解析。
下面是适合我的配置:
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;
global.sinon = require('sinon');
相关文章:
- 模糊事件的Javascript测试
- 我的单元测试选项是什么
- 测试索引值是否等于某个数字的倍数
- 在localhost Dev Box上测试JSONP请求的最佳方式
- 测试数组中每个项的内容
- 测试Angular Service解决错误回调中的promise
- 使用Jest测试React Native应用程序
- 为函数代码编写测试
- 如何在Angular单元测试中从另一个控制器的rootScope将方法添加到rootScope中
- 如何使用JS/nightwatchjs并行运行多个测试
- 使用量角器的当前url单元测试的getTitle
- 带有expect的mocha不适用于测试错误
- 在我的Javascript单元测试中,expect(true).toBeTruthy()失败
- 使用 Jasmine 进行单元测试,expect().toBeVisible()
- expect()in.then()-jasmine单元测试,AngularJS
- 通过使用expect和比较数组中的每个值来进行Karma测试
- 当promise.then中的expect失败时,Protractor / cucumber测试套件停止运行
- expect - response在AngularJS单元测试(Jasmine)中不起作用
- 没有expect()的Jasmine测试将成功
- Webstorm IDE和mocha使用global.expect进行测试