Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When testing angularjs controller - Can't find variable: module / inject by chutzpah

I have angularJs controller

angular.module('App.ctrl.guests', [])
    .controller('guestsController', ['$scope', '$http', '$location', '$timeout', 'guestsService', function ($scope, $http, $location, $timeout, guestsService) {
        $scope.tiles = [];
    }])

and jasmine test

/// <reference path="~/Scripts/angular.js" />
/// <reference path="../../ProjectWeb/Scripts/app/guests/guestsCtrl.js" />
/// <reference path="~/Scripts/angular-mocks.js" />
/// <reference path="~/Scripts/jasmine.js" />
'use strict';
describe('App.ctrl.guests', function () {
    var scope, controller;
    beforeEach(function () {
        module('App.ctrl.guests')
    });
    beforeEach(inject(function ($rootScope, $controller) {
        scope = $rootScope.$new();
        controller = $controller('guestsController', {
            $scope: scope
        });
    }));

    it('should have empty array', function () {
        expect(scope.tiles).toBe([]);
    });
})

and every time i run in Visual studio chutzpah i get:

ReferenceError: Can't find variable: module in file:///.../JasmineTests/guestsControllerTest.js (line 5)

ReferenceError: Can't find variable: inject in file:///.../JasmineTests/guestsControllerTest.js (line 12)

Is thera a problem with reference angular.js and jasmine dont know what is module/inject keywords? It is my first time with js testing :/

like image 961
netmajor Avatar asked Jul 25 '14 12:07

netmajor


1 Answers

I found in this article on how to drag and drop JavaScript files for testing and correct path.

like image 66
netmajor Avatar answered Oct 16 '22 23:10

netmajor