I'm a newbie in testing Angular Apps with Jasmine, and I can't figure out the cause of this problem...
The controller
programsModule.controller('ticketCtrl', ['$scope', function ($scope) {
$scope.disableSendBtn = true;
});
And this is the 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 output of the test
TypeError: Cannot read property 'disableSendBtn' of undefined
And if I test if the $scope
variable is defined or not by
it('Should $scope be defined', function () {
expect($scope).toBeDefined();
});
I get this error too
Expected undefined to be defined.
So what's the problem here?
HERE is the jsFiddle http://jsfiddle.net/LeoAref/bn1wxycs/
Edit
I used incorrect module here
beforeEach(module('app'));
and I fixed that by using the correct module
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