Sono un principiante nel testare applicazioni angolari con gelsomino, e non riesco a capire la causa di questo problema ...attesi undefined essere definito durante il test regolatore angolare con gelsomino
Il controller
programsModule.controller('ticketCtrl', ['$scope', function ($scope) {
$scope.disableSendBtn = true;
});
E questo è il test di unità
'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);
});
});
});
E questo è l'outp ut del test
TypeError: Cannot read property 'disableSendBtn' of undefined
E se verifico se la variabile $scope
è definita o no da
it('Should $scope be defined', function() {
expect($scope).toBeDefined();
});
ottengo questo errore troppo
Expected undefined to be defined.
Allora qual è il problema?
è QUI il jsFiddle http://jsfiddle.net/LeoAref/bn1wxycs/
Modifica
ho usato modulo errato qui beforeEach(module('app'));
e mi fisso che, utilizzando il modulo corretto beforeEach(module('supportModule'));
E ho avuto un altro errore:
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
Prova '$ regolatore _ ('ticketCtrl', {$ portata: $ portata });' senza usare le virgolette singole –
@WayneEllery, grazie ma ho ottenuto lo stesso errore ... – LeoAref
Hai un errore di battitura: $ rootScope = \ _ $ controller_; <- cambia in \ _ $ rootScope_ –