Skip to content

Instantly share code, notes, and snippets.

@rctay
Last active December 19, 2015 01:08
Show Gist options
  • Save rctay/5873508 to your computer and use it in GitHub Desktop.
Save rctay/5873508 to your computer and use it in GitHub Desktop.
angular.scenario: add beforeAll
/**
* Defines a block to execute before each it or nested describe.
*
* beforeAll()s will be called before beforeEach()s.
*
* Note: unlike beforeEach(), this needs to be called on "this", ie.
*
* this.beforeAll(...)
*
* This can be fixed but would require too much hacking.
*
* @param {function()} body Body of the block.
*/
angular.scenario.Describe.prototype.beforeAll = function(body) {
if (!this._NG_SCENARIO_ALL) {
this.beforeAllFns = [];
var self = this;
var allHandler = function() {
angular.forEach(self.beforeAllFns, function(fn) { fn.call(self) });
self.beforeEachFns[0] = angular.noop;
};
this.beforeEachFns.unshift(allHandler);
this._NG_SCENARIO_ALL = true;
}
this.beforeAllFns.push(body);
};
@EvAlex
Copy link

EvAlex commented Mar 4, 2014

Good stuff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment