I am new to testing Angular applications with Jasmine and I cannot figure out the cause of this problem ...
Controller
programsModule.controller('ticketCtrl', ['$scope', function ($scope) { $scope.disableSendBtn = true; });
And this is unit test
'use strict'; describe('app', function () { // variables var $rootScope, $scope, $controller; beforeEach(module('supportModule')); describe('ticketCtrl', function () { beforeEach(inject(function (_$rootScope_, _$controller_) { $rootScope = _$rootScope_; $scope = $rootScope.$new(); $controller = _$controller_('ticketCtrl', { '$scope': $scope }); })); it('Should disable send btn', function () { expect($scope.disableSendBtn).toEqual(true); }); }); });
And this is the test result
TypeError: Cannot read property 'disableSendBtn' of undefined
And if I check if the variable $scope defined or not
it('Should $scope be defined', function () { expect($scope).toBeDefined(); });
I get this error too
Expected undefined to be defined.
So what is the problem?
There is jsFiddle here http://jsfiddle.net/LeoAref/bn1wxycs/
Edit
I used the wrong module here beforeEach(module('app'));
and I fixed it using the correct beforeEach(module('supportModule'));
And I got another error:
Error: [ng:areq] Argument 'ticketCtrl' is not a function, got undefined http://errors.angularjs.org/1.4.1/ng/areq?p0=ticketCtrl&p1=not%20a%20function%2C%20got%20undefined
source share