Last active
December 24, 2015 21:39
-
-
Save herzi/6867347 to your computer and use it in GitHub Desktop.
Testing decorated services in AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var myApp = angular.module('myApp', []); | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); | |
}); | |
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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