Should not complain about undefined window when I have it defined like that:
NODE_PATH=./src/modules:./lib \
./node_modules/.bin/mocha \
--globals window,navigator \
--colors \
--compilers coffee:coffee-script/register \
./**/__mocha__/*
Happens on latest version.
From Mocha's --help documentation:
--check-leaks check for global variable leaks
--globalsallow the given comma-delimited global [names]
And from the elaborations available at https://mochajs.org:
--globals
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. It also accepts wildcards. You could do --globals '*bar' and it would match foobar, barbar, etc. You can also simply pass in '*' to ignore all globals.
--check-leaks
By default, Mocha will not check for global variables leaked while running tests, to enable this pass --check-leaks, to specify globals that are acceptable use --globals, for example --globals jQuery,MyLib.
TL;DR: --globals does not define anything and is niether documented as doing so nor intended to. Rather, it's used to tell Mocha to make a specific exception to the optional behavior of complaining if your code adds global variables.
Given that your code is trying to use window, which is typically the name of the global context in a browser environment, I'm going to go out on a limb and guess that you're trying to do one of the following (so as to offer some pointers for each):
Mocha doesn't do any of these things by itself*; it does, however, work great with each of these three tools for these three different use cases.
*(except testing JS code in a browser manually where you can't get the results programmatically, which Mocha supports directly but which really is only useful if you want to be able to distribute a package and run its tests without having to have Node or something like that)
very good points - give me time to figure out which of those tests should be moved to selenium, karma or jsdom. thanks heaps for your honest feedback and links. again, very good comments. thanks
Most helpful comment
From Mocha's
--helpdocumentation:And from the elaborations available at https://mochajs.org:
TL;DR:
--globalsdoes not define anything and is niether documented as doing so nor intended to. Rather, it's used to tell Mocha to make a specific exception to the optional behavior of complaining if your code adds global variables.Given that your code is trying to use
window, which is typically the name of the global context in a browser environment, I'm going to go out on a limb and guess that you're trying to do one of the following (so as to offer some pointers for each):Mocha doesn't do any of these things by itself*; it does, however, work great with each of these three tools for these three different use cases.
*(except testing JS code in a browser manually where you can't get the results programmatically, which Mocha supports directly but which really is only useful if you want to be able to distribute a package and run its tests without having to have Node or something like that)