Node.js - why do I get leaks when testing with mocha and zombie?

£可爱£侵袭症+ 提交于 2020-01-03 15:31:10

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/10545449/node-js-why-do-i-get-leaks-when-testing-with-mocha-and-zombie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!