Note that there are some explanatory texts on larger screens.

plurals
  1. POInjecting angular controller in jasmine
    primarykey
    data
    text
    <p>I have read through many examples in regards to injecting controllers into a jasmine unit test, however I keep getting "Error: [ng:areq] <a href="http://errors.angularjs.org/undefined/ng/areq?p0=MainCtrl&amp;p1=not%20a%20function%2C%20got%20undefined" rel="nofollow">http://errors.angularjs.org/undefined/ng/areq?p0=MainCtrl&amp;p1=not%20a%20function%2C%20got%20undefined</a>".</p> <p>Here is my code:</p> <p>main.spec.js:</p> <pre><code>'use strict' describe("Testing Main Controller", function(){ var scope, controller; var dummyFunction = function(){}; var defaultDocument = { _id: "123456" }; beforeEach(module('app.controllers')); beforeEach(module('app')); beforeEach(inject(function($rootScope, $controller) { scope = $rootScope.$new(); controller = $controller('MainCtrl', { $scope: scope, SearchService: dummyFunction, ResultsService: dummyFunction, FacetService: dummyFunction, EsDateService: dummyFunction, Likes: dummyFunction, Bookmarks: dummyFunction }); })); describe("Likes", function(){ it('shall give the user the ability to like a document that is currently being displayed.', function(){ scope.updateLike([defaultDocument]); expect(defaultDocument.isLiked).toBe(true); }); it('shall give the user the ability to remove a like from a document that is currently being displayed.', function(){ defaultDocument.isLiked = true; scope.updateLike([defaultDocument]); expect(defaultDocument.isLiked).toBe(true); }); }); }); </code></pre> <p>main_controller.js:</p> <pre><code>'use strict'; angular.module('app.controllers') .controller('MainCtrl', function($scope, SearchService, ResultsService, FacetService, EsDateService, Likes, Bookmarks) { }); </code></pre> <p>app.js:</p> <pre><code>angular.module('app.services', ['ngResource', 'elasticjs.service']); angular.module('app.controllers', [ 'app.services']); var app = angular.module('app', [ 'ui.bootstrap', 'elasticjs.service', 'app.services', 'app.controllers', 'app.config', 'facet.directives', 'ngRoute']); app.config(['$routeProvider', function($routeProvider) { $routeProvider .when('/', { controller: 'SearchCtrl', templateUrl: 'views/search/search.html' }) .when('/journal', { controller: 'JournalCtrl', templateUrl: 'views/journal/journal.html' }) .otherwise({ redirectTo: '/' }); } ]); app.config(['$locationProvider', function($locationProvider) { $locationProvider.hashPrefix("!"); } ]); </code></pre> <p>When I attach MainCtrl to app rather than app.controllers it seems to find MainCtrl. What am I doing wrong? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload