1

I am trying to test one of my Angular controllers. For a start, I want to just see, that I can call a simple function in the controller, which returns the sum of two numbers.

This is relevant part of the controller, with the simple sum function (I have left all the other functions out for simplicity):

detailModule.controller('detailController',
    function detailController($rootScope, $scope, detailService, sharedPropertiesService, facebookService, helperService, uiStateService) {

    $scope.sum = function (first, second) {
        return first + second;
    }
});

Besides $rootscope and $scope, the controller takes serveral services.

Now I want to call this sum function from Jasmine, and made this js for the purpose.

/// <reference path="D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\Scripts/jasmine/jasmine.js" />
/// <reference path="D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\Scripts/angular.min.js" />
/// <reference path="D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\Scripts/angular-mocks.js" />
/// <reference path="app.js" />
/// <reference path="detailController.js" />

'use strict';

describe('detailModule', function () {
    beforeEach(module('detailModule'));

    describe('detailController', function () {
        var scope, controller, rootScope;
        var detailService, sharedPropertiesService, facebookService, helperService, uiStateService;

        beforeEach(inject(function (_$rootScope, _$scope, _detailService, _sharedPropertiesService, _facebookService, _helperService, _uiStateService, $controller) {
            rootScope = _$rootScope;
            scope = $rootScope.$new();
            detailService = _detailService;
            sharedPropertiesService = _sharedPropertiesService;
            facebookService = _facebookService;
            helperService = _helperService;
            uiStateService = _uiStateService;

            controller = $controller('detailController', {
                $rootScope : rootScope,
                $scope: scope,
                detailService: detailService,
                sharedPropertiesService: sharedPropertiesService,
                facebookService: facebookService,
                helperService: helperService,
                uiStateService: uiStateService
            });
        }));

        it('should return 10', function () {
            var result = scope.sum(3, 7);
            expect(result).toEqual(10);
        });
    })
})

The app.js included contains the detailModule.

I have installed chutzpah to run my test. Here is what is says:

------ Test started: File: D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\App\Detail\detailTest.js ------
Test 'detailModule detailController:should return 10' failed
    Error: [$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=detailModule&p1=%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.5.7%2F%24injector%2Fmodulerr%3Fp0%3DhomeworkModule%26p1%3D%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.5.7%252F%2524injector%252Fnomod%253Fp0%253DhomeworkModule%250Afile%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A25%253A84%250Ab%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A24%253A116%250Afile%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A24%253A435%250Afile%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A39%253A376%250Ar%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A7%253A359%250Ag%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A39%253A223%250Afile%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A39%253A392%250Ar%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A7%253A359%250Ag%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A39%253A223%250Adb%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular.min.js%253A43%253A247%250AworkFn%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FScripts%252Fangular-mocks.js%253A3067%253A60%250AattemptSync%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1886%253A28%250Arun%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1874%253A20%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1859%253A13%250AqueueRunnerFactory%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A697%253A42%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A359%253A28%250Afn%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A2479%253A44%250AattemptAsync%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1916%253A28%250Arun%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1871%253A21%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1859%253A13%250AqueueRunnerFactory%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A697%253A42%250Afn%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A2464%253A31%250AattemptAsync%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1916%253A28%250Arun%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1871%253A21%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1859%253A13%250AqueueRunnerFactory%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A697%253A42%250Afn%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A2464%253A31%250AattemptAsync%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1916%253A28%250Arun%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1871%253A21%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A1859%253A13%250AqueueRunnerFactory%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A697%253A42%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A2326%253A25%250Aexecute%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fjasmine.js%253A757%253A24%250AinitializeJasmine%2540file%253A%252F%252F%252FC%253A%252FUsers%252Fbbrinch%252FAppData%252FLocal%252FMicrosoft%252FVisualStudio%252F14.0%252FExtensions%252F5t5s0xe3.mo1%252FTestFiles%252Fjasmine%252Fv2%252Fboot.js%253A122%253A24%250Aonload%2540file%253A%252F%252F%252FD%253A%252FUsers%252Fbbrinch%252FDocuments%252FVisual%252520Studio%2525202015%252FProjects%252FHomework%252FHomework%252FApp%252FDetail%252F_Chutzpah.506d30473962e5a1c0c0767c74fcc633.test.html%253A65%253A45%0Afile%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A40%3A172%0Ar%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A7%3A359%0Ag%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A39%3A223%0Afile%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A39%3A392%0Ar%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A7%3A359%0Ag%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A39%3A223%0Adb%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular.min.js%3A43%3A247%0AworkFn%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FScripts%2Fangular-mocks.js%3A3067%3A60%0AattemptSync%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1886%3A28%0Arun%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1874%3A20%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1859%3A13%0AqueueRunnerFactory%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A697%3A42%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A359%3A28%0Afn%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A2479%3A44%0AattemptAsync%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1916%3A28%0Arun%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1871%3A21%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1859%3A13%0AqueueRunnerFactory%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A697%3A42%0Afn%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A2464%3A31%0AattemptAsync%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1916%3A28%0Arun%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1871%3A21%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1859%3A13%0AqueueRunnerFactory%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A697%3A42%0Afn%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A2464%3A31%0AattemptAsync%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1916%3A28%0Arun%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1871%3A21%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A1859%3A13%0AqueueRunnerFactory%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A697%3A42%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A2326%3A25%0Aexecute%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fjasmine.js%3A757%3A24%0AinitializeJasmine%40file%3A%2F%2F%2FC%3A%2FUsers%2Fbbrinch%2FAppData%2FLocal%2FMicrosoft%2FVisualStudio%2F14.0%2FExtensions%2F5t5s0xe3.mo1%2FTestFiles%2Fjasmine%2Fv2%2Fboot.js%3A122%3A24%0Aonload%40file%3A%2F%2F%2FD%3A%2FUsers%2Fbbrinch%2FDocuments%2FVisual%2520Studio%25202015%2FProjects%2FHomework%2FHomework%2FApp%2FDetail%2F_Chutzpah.506d30473962e5a1c0c0767c74fcc633.test.html%3A65%3A45 in file:///D:/Users/bbrinch/Documents/Visual%20Studio%202015/Projects/Homework/Homework/Scripts/angular.min.js (line 40)
    r@file:///D:/Users/bbrinch/Documents/Visual%20Studio%202015/Projects/Homework/Homework/Scripts/angular.min.js:7:359
    g@file:///D:/Users/bbrinch/Documents/Visual%20Studio%202015/Projects/Homework/Homework/Scripts/angular.min.js:39:223
    db@file:///D:/Users/bbrinch/Documents/Visual%20Studio%202015/Projects/Homework/Homework/Scripts/angular.min.js:43:247
    workFn@file:///D:/Users/bbrinch/Documents/Visual%20Studio%202015/Projects/Homework/Homework/Scripts/angular-mocks.js:3067:60
    attemptSync@file:///C:/Users/bbrinch/AppData/Local/Microsoft/VisualStudio/14.0/Extensions/5t5s0xe3.mo1/TestFiles/jasmine/v2/jasmine.js:1886:28
    TypeError: undefined is not an object (evaluating 'scope.sum') in file:///D:/Users/bbrinch/Documents/Visual%20Studio%202015/Projects/Homework/Homework/App/Detail/detailTest.js (line 37)
    attemptSync@file:///C:/Users/bbrinch/AppData/Local/Microsoft/VisualStudio/14.0/Extensions/5t5s0xe3.mo1/TestFiles/jasmine/v2/jasmine.js:1886:28
    run@file:///C:/Users/bbrinch/AppData/Local/Microsoft/VisualStudio/14.0/Extensions/5t5s0xe3.mo1/TestFiles/jasmine/v2/jasmine.js:1874:20
    execute@file:///C:/Users/bbrinch/AppData/Local/Microsoft/VisualStudio/14.0/Extensions/5t5s0xe3.mo1/TestFiles/jasmine/v2/jasmine.js:1859:13
    queueRunnerFactory@file:///C:/Users/bbrinch/AppData/Local/Microsoft/VisualStudio/14.0/Extensions/5t5s0xe3.mo1/TestFiles/jasmine/v2/jasmine.js:697:42
    execute@file:///C:/Users/bbrinch/AppData/Local/Microsoft/VisualStudio/14.0/Extensions/5t5s0xe3.mo1/TestFiles/jasmine/v2/jasmine.js:359:28
in D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\App\Detail\detailTest.js (line 36)

0 passed, 1 failed, 1 total (chutzpah).

========== Total Tests: 0 passed, 1 failed, 1 total ==========

I have no idea what I am missing here.


Update:

I tried to simplify the controller as suggested by estus:

It now looks like this:

/// <reference path="D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\Scripts/jasmine/jasmine.js" />
/// <reference path="D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\Scripts/angular.min.js" />
/// <reference path="D:\Users\bbrinch\Documents\Visual Studio 2015\Projects\Homework\Homework\Scripts/angular-mocks.js" />
/// <reference path="app.js" />
/// <reference path="detailController.js" />

'use strict';

describe('detailModule', function () {
    beforeEach(module('detailModule'));

    describe('detailController', function () {
        var scope, controller;

        beforeEach(inject(function (_$rootScope) {
            scope = _$rootScope.$new();

            controller = $controller('detailController', {
                $scope: scope,
            });
        }));

        it('should return 10', function () {
            var result = scope.sum(3, 7);
            expect(result).toEqual(10);
        });
    })
})

However I still get this error:

Failed to instantiate module detailModule due to: [$injector:modulerr] http://errors.angularjs.org/1.5.7/$injector/modulerr?p0=h...

UPDATE 2

I solved it. Problem was that I was missing references. Basically all modules, services, controllers etc involved one way or the other must be referenced.

Would be kind of nice if it could automatically traverse and resolve all needed references.

2 Answers 2

2

Error stack can be followed, and the message says the initial reason:

Module 'homeworkModule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

$controller shares the injector with current spec, there's no reason to specify dependencies for $controller, unless they are local or mocked. It should be:

        controller = $controller('detailController', {
            $scope: scope
        });
Sign up to request clarification or add additional context in comments.

3 Comments

@brinch $injector:modulerr errors are about module problems. You get this error because homeworkModule was not loaded.
So all dependencies in the hierarchy must be referenced then (modules, controllers, directives, services etc)?
It looks like detailModule depends on homeworkModule. And the file that contains homeworkModule module should be loaded in specs.
0

TypeError: undefined is not an object (evaluating 'scope.sum')

This means scope is undefined.

This is most probably because of this code,

rootScope = _$rootScope;
scope = $rootScope.$new(); // it should be either _$rootScope.new() or rootScope.new()

Just check by changing this.

1 Comment

That didn't change anything. I tried to simplify the test code instead. Please see updated question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.