Created
March 29, 2015 10:43
-
-
Save climboid/71c41285e040bc57b47f to your computer and use it in GitHub Desktop.
Unit test failing
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
'use strict'; | |
describe('Offers : controller', function(){ | |
beforeEach(module('client')); | |
var $scope, | |
$rootScope, | |
controller, | |
genericService; | |
beforeEach(inject(function($injector) { | |
$rootScope = $injector.get('$rootScope'); | |
genericService = $injector.get('genericService'); | |
$scope = $rootScope.$new(); | |
var $controller = $injector.get('$controller'); | |
var createController = function() { | |
return $controller('OffersCtrl', { | |
$scope: $scope, | |
genericService : genericService | |
}); | |
}; | |
controller = createController(); | |
})); | |
it('should have a fixed slider value', function () { | |
expect($scope.sliderValue).toEqual(4600); | |
}); | |
}); | |
// | |
// The error I get is | |
// Error: [$injector:unpr] Unknown provider: genericServiceProvider <- genericService | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@climboid a few thoughts...
instead of injecting the
$injector
then manually looking up the service and rootscope you can inject those directly in the beforeEachbeforeEach(inject(function($rootScope, $controller, genericService) {..
If there a service called
genericService
in your app calledclient
what you have should work. Is it maybe calledGenericService
?You don't need to inject
genericService
at all. Since you are passing what angular provides you directly into the controller just omit that line and angular will do the right thing.Lastly you don't need to return anything in your
createController
function. The controller is created with the scope as a side-effect and you can now read and write on the scope to test the controller.