The idea is to mock the service based on the gist. Where the service is redefined and then the injection happens, the new overwritten service is used by the directive/controller.
How it's possible to inject the overwritten on the directive? The following snippet shows how it's inserted on the controller:
beforeEach(inject(function($controller, $rootScope, _UserService_) { // inject mocked service
scope = $rootScope.$new();
ctrl = $controller('MyController', {
$scope: scope,
UserService: _UserService_
});
}));
Aucun commentaire:
Enregistrer un commentaire