Node.js-为什么在用摩卡和僵尸进行测试时会泄漏? [英] Node.js - why do I get leaks when testing with mocha and zombie?
问题描述
我试图使僵尸程序与Mocha一起使用,但是除非我使用mocha --ignore-leaks命令选项,否则我的测试将始终失败,并显示以下错误:
Error: global leaks detected: k, i, name, chars, char
我的测试看起来与该线程中解释的完全相同: Mocha和ZombieJS
我希望我可以在这里发布我的问题,但是作为一个新手,我不能在主题上发表评论,只能提出一个新问题.
您知道我为什么会收到这些泄漏吗?我正在使用摩卡咖啡1.0.3和僵尸1.0.0.
泄漏可能来自您自己的代码,也可能来自您使用的node_modules. Mocha应该对泄漏的位置给出一些提示,例如忘记使用 var 声明局部变量.
// global leaks
a = 1;
// no leaks
var a = 1;
您还可能会对用coffeescript编写Node.js应用程序感兴趣,因为它可以帮助您避免发生此类错误. (它会使用var 自动初始化变量). http://coffeescript.org/ >
这里有一个模板可以帮助您入门 https://github.com/twilson63/express-咖啡
I've tried to make zombie work with mocha, but unless I use the mocha --ignore-leaks command options, my test always fails with the error:
Error: global leaks detected: k, i, name, chars, char
My test looks exactly like the one explained in this thread: Mocha and ZombieJS
I wish I could have posted my question there, but as a newbie, I cannot comment on the thread, only ask a new question.
Do you have any idea why I get these leaks? I'm using mocha 1.0.3 and zombie 1.0.0.
The leaks can come either from your own code or from node_modules that you use. Mocha should give some hints on where the leaks are, such as forgetting to declare local variable with var.
// global leaks
a = 1;
// no leaks
var a = 1;
You might also be interested writing Node.js app in coffeescript since it helps you avoid mistakes like that. (It automatically initializes variables, using var) http://coffeescript.org/
There is a template that helps you get started here https://github.com/twilson63/express-coffee
这篇关于Node.js-为什么在用摩卡和僵尸进行测试时会泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!