Skip to content

Instantly share code, notes, and snippets.

@herzi
Last active December 24, 2015 21:39
Show Gist options
  • Save herzi/6867347 to your computer and use it in GitHub Desktop.
Save herzi/6867347 to your computer and use it in GitHub Desktop.
Testing decorated services in AngularJS
(function () {
var myApp = angular.module('myApp', []);
}());
(function () {
var myApp = angular.module('myApp');
myApp.myDecorated$log = function ($delegate) {
// monkey-patch $delegate here
$delegate.monkeyPatched = true;
return $delegate;
};
myApp.config(function ($provide) {
$provide.decorator('$log', myApp.myDecorated$log);
});
}());
/* inspired by http://jsfiddle.net/vojtajina/DQHdk/ */
describe('Overriding $log', function () {
var myApp = angular.module('myApp');
beforeEach(function () {
module('myApp', function ($provide) {
$provide.decorator('$log', myApp.myDecorated$log);
});
});
it('should work', inject(function ($log) {
$log.should.have.property('monkeyPatched', true);
}));
});
// vim:set sw=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment