jestem nowicjuszem w testowaniu kątowe Apps z Jasmine, a ja nie mogę zrozumieć przyczynę tego problemu ...Oczekiwane niezdefiniowany zostać określone podczas testowania kontrolera kątowy z Jasmine
kontrolera
programsModule.controller('ticketCtrl', ['$scope', function ($scope) {
$scope.disableSendBtn = true;
});
I to jest test jednostka
'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);
});
});
});
I to jest outp ut testu
TypeError: Cannot read property 'disableSendBtn' of undefined
A gdybym sprawdzić, czy zmienna $scope
jest zdefiniowana lub nie
it('Should $scope be defined', function() {
expect($scope).toBeDefined();
});
dostaję ten błąd zbyt
Expected undefined to be defined.
Więc w czym problem?
Oto jsFiddle http://jsfiddle.net/LeoAref/bn1wxycs/
Edit
użyłem nieprawidłowy moduł tutaj beforeEach(module('app'));
i naprawiłem, że stosując właściwy moduł beforeEach(module('supportModule'));
I mam kolejny błąd:
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
Spróbuj '$ kontroler _ ('ticketCtrl' { $ zakres: $ zakres });' bez użycia apostrofów –
@WayneEllery, dzięki, ale mam ten sam błąd ... – LeoAref
Masz literówkę: $ rootScope = \ _ $ controller_; <- Zmień to na \ _ $ rootScope_ –