I'm a complete rookie when it comes to unit testing with Jasmine and unit testing in general. My recent task has me trying to unit test an AngularJS controller. Below you'll see my code and what I've tried and most of it has failed to get me where I need to go. Any help would be appreciated!!
Controller
angular
.module('TDE')
.controller('LocationController', ['$rootScope', '$scope', '$location', '$window', '$document', 'LocationService', 'HeaderFooterService', 'SearchService', 'TranslationService', 'MTDE_CONFIG', 'LocationPartnerAssignmentService', 'ExperimentService', function ($rootScope, $scope, $location, $window, $document, $LocationService, $HeaderFooterService, $SearchService, $TranslationService, $MTDE_CONFIG, $LocationPartnerAssignmentService, $ExperimentService) {
//some non important code
//What I'm trying to test
$scope.boolTest= function(var){
return true; //this method only returns true
}
//all I'm after is basic understanding, I've done countless searches but I can't get it
//other code
Helper File (Test File)
beforeEach(function () {
angular.mock.module('LocationController'); //
inject(function ($injector) {
//$rootScope = $injector.get('$rootScope');
//$scope = $rootScope.$new();
//ctrl = $injector.get('$controller')("LocationController", { $scope: $scope });
//Neither ctrl really functions that well
injector = $injector;
ctrl = $injector.get('$controller');
scope = $injector.get('$rootScope').$new();
});
});
Spec.html
<!-- jasmine source -->
<link rel="shortcut icon" type="image/png" href="spec/lib/jasmine-1.2.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="spec/lib/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="spec/lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="spec/lib/jasmine-1.2.0/jasmine-html.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.1.0/angular-mocks.js"></script>
<!-- include source files here... -->
<script type="text/javascript" src="js/Location/LocationController.js"></script>
<!-- include spec files here... -->
<script type="text/javascript" src="spec/RTHelper.js"></script>
As of right now I am stuck, I can get really basic tests to work like a + b and verify the result, however I can not gain (at least I think) access to the $scope like I need for that method.
Current Error is No module: LocationController
I've tried it by using 'TDE' but nothing, someone please help me!