在摩卡全球泄漏错误 [英] global leak errors in mocha
问题描述
我试图单元测试苹果推送通知库时,我得到了一个全球泄漏错误试图开辟一个APN连接。
那是我的一个配置错误或错误节点APN或摩卡?
我不知道我明白了什么checkGlobals做......它只是检查,看是否有全局变量被设置?
0)订阅之前的所有挂钩:
错误:全球泄漏检测:hasCert
在Runner.checkGlobals(/usr/lib/node_modules/mocha/lib/runner.js:96:21)
在亚军<&匿名GT; (/usr/lib/node_modules/mocha/lib/runner.js:41:44)
在Runner.emit(events.js:64:17)
在/usr/lib/node_modules/mocha/lib/runner.js:159:12
在Hook.run(/usr/lib/node_modules/mocha/lib/runnable.js:114:5)
在明(/usr/lib/node_modules/mocha/lib/runner.js:157:10)
在阵列<&匿名GT; (/usr/lib/node_modules/mocha/lib/runner.js:165:5)
在EventEmitter._tickCallback(node.js的:126:26)
是,摩卡拥有哪些警报的全球泄漏检测机制,如果被测您code介绍了全局变量失败。
如果 hasCert
在一个库中声明,你必须在它的创作无法控制,你可以告诉摩卡忽略它。
在命令行,
$摩卡--globals hasCert
要引用文档:
[此选项]接受一个逗号分隔接受全局变量名的列表。例如,假设您的应用程序故意暴露了一个全局命名的应用程序和YUI,你可能要添加--globals应用,YUI。
块引用>在浏览器中:
mocha.setup({全局:['hasCert']});
I was trying to unit test the apple push notification library when I got a global leak error trying to open up an APN connection.
Is that a configuration error on my part or an error in node-apn or mocha?
I'm not sure I understand what checkGlobals is doing... is it just checking to see if any global variable are being set?
0) Feed "before all" hook: Error: global leak detected: hasCert at Runner.checkGlobals (/usr/lib/node_modules/mocha/lib/runner.js:96:21) at Runner.<anonymous> (/usr/lib/node_modules/mocha/lib/runner.js:41:44) at Runner.emit (events.js:64:17) at /usr/lib/node_modules/mocha/lib/runner.js:159:12 at Hook.run (/usr/lib/node_modules/mocha/lib/runnable.js:114:5) at next (/usr/lib/node_modules/mocha/lib/runner.js:157:10) at Array.<anonymous> (/usr/lib/node_modules/mocha/lib/runner.js:165:5) at EventEmitter._tickCallback (node.js:126:26)
解决方案Yes, Mocha features a global leak detection mechanism which alerts and fails if your code under test introduces global variables.
If
hasCert
is declared in a library and you have no control over its creation, you can tell Mocha to ignore it.On the command line,
$ mocha --globals hasCert
To quote the documentation:
[This option] accepts a comma-delimited list of accepted global variable names. For example suppose your app deliberately exposes a global named app and YUI, you may want to add --globals app,YUI.
In a browser:
mocha.setup({globals: ['hasCert']});
这篇关于在摩卡全球泄漏错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!