mocha-repeat
Loop tests through diferrent variations of data in mocha.js. Perfect for testing against multiple versions of 3rd-party libraries.
var mdescribe = ; var libs = 'jquery-1.9': 'jquery-2.0': 'jquery-2.1': ; ;
This will be expanded to:
; ; ;
Install
$ npm i --save-dev mocha-repeat
Why?
This effect is easily achievable in plain JavaScript, though the resulting code will be more verbose.
libs = ... ;for var version in libs if libs var jQuery = libsversion; { ; }jQuery version;
It's easier to write it this way:
libs = ... ;;
Splatting
If the values are arrays, they will be spread across the function's arguments.
In this example, the function's 2 arguments (jQuery, options
) will be
populated by the array items.
var libs = {
'jquery-1.9': [ require('../vendor/jquery-1.9.js'), { legacy: true } ],
'jquery-2.0': [ require('../vendor/jquery-2.0.js'), { } ],
'jquery-2.1': [ require('../vendor/jquery-2.1.js'), { future: true } ],
};
mdescribe("Tests", stubs, function (jQuery, options) {
if (options.legacy) {
}
});
Permutations
You can nest calls to mocha-repeat. This is great for testing combinations of multiple library versions. In this example, it tests against every possble combination of underscore [1.0..1.2] with backbone [1.0..1.2].
var libs = underscore: '1.0': '../vendor/underscore/1.0.0.js' '1.1': '../vendor/underscore/1.1.0.js' '1.2': '../vendor/underscore/1.2.0.js' backbone: '1.0': '../vendor/backbone/1.0.0.js' '1.1': '../vendor/backbone/1.1.0.js' '1.2': '../vendor/backbone/1.2.0.js' ; var _ Backbone;
Output:
$ mocha -R list . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors . Underscore Backbone loads without errors 9 passing
Thanks
mocha-repeat © 2014+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz