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']});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…