angular.js/test/scenario/mocks.js
Igor Minar 0a6cf70deb Rename angular.foreach to angular.forEach to make the api consistent.
camelcase is used for other angular functions and forEach is also
used by EcmaScript standard.

- rename the internal as well as the external function name
- tweak the implementation of the function so that it doesn't
  clober it self when we extend the angular object with an
  object that has a forEach property equal to this forEach function

Closes #85
2011-01-10 10:26:55 -08:00

41 lines
1.1 KiB
JavaScript

angular.scenario.testing = angular.scenario.testing || {};
angular.scenario.testing.MockAngular = function() {
this.reset();
this.service = this;
};
angular.scenario.testing.MockAngular.prototype.reset = function() {
this.log = [];
};
angular.scenario.testing.MockAngular.prototype.$browser = function() {
this.log.push('$brower()');
return this;
};
angular.scenario.testing.MockAngular.prototype.poll = function() {
this.log.push('$brower.poll()');
return this;
};
angular.scenario.testing.MockAngular.prototype.notifyWhenNoOutstandingRequests = function(fn) {
this.log.push('$brower.notifyWhenNoOutstandingRequests()');
fn();
};
angular.scenario.testing.MockRunner = function() {
this.listeners = [];
};
angular.scenario.testing.MockRunner.prototype.on = function(eventName, fn) {
this.listeners[eventName] = this.listeners[eventName] || [];
this.listeners[eventName].push(fn);
};
angular.scenario.testing.MockRunner.prototype.emit = function(eventName) {
var args = Array.prototype.slice.call(arguments, 1);
angular.forEach(this.listeners[eventName] || [], function(fn) {
fn.apply(this, args);
});
};