Próba ustawienia testów jednostkowych dla https://github.com/beeman/loopback-angular-admin.Angular/Karma/Jasmine: TypeError: 'undefined' nie jest obiektem (oceniającym "scope.awesomeThings").
app/modules/o/controllers/about.controller.js (dodałem $scope.awesomeThings
załadować zakresu coś do testu):
'use strict';
angular.module('com.module.about')
/**
* @ngdoc function
* @name com.module.about.controller:AboutCtrl
* @description
* # AboutCtrl
* Controller of the clientApp
*/
.controller('AboutCtrl', function($scope) {
$scope.angular = angular;
$scope.awesomeThings = [1, 2];
});
Test jaśminowym na klient/test/modułów/o/controllers/about.ctrl.js
'use strict';
describe('Controller: AboutCtrl', function() {
var AboutCtrl,
scope;
// load the controller's module
beforeEach(module('gettext'));
beforeEach(module('ui.router'));
beforeEach(module('com.module.about'));
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
AboutCtrl = $controller('AboutCtrl', {
'$scope': scope
});
}));
it('should attach a list of awesomeThings to the scope', function() {
expect(scope.awesomeThings.length).toBe(3);
});
});
Gdy ten prosty test, otrzymuję:
TypeError: 'undefined' is not a function (evaluating '$rootScope.addDashboardBox(gettextCatalog.getString('About'), 'bg-maroon',
'ion-information', 0, 'app.about.index')')
at client/app/modules/about/controllers/about.config.js:6
at invoke (client/app/bower_components/angular/angular.js:4203)
at client/app/bower_components/angular/angular.js:4025
at forEach (client/app/bower_components/angular/angular.js:323)
at createInjector (client/app/bower_components/angular/angular.js:4025)
at workFn (client/app/bower_components/angular-mocks/angular-mocks.js:2425)
TypeError: 'undefined' is not an object (evaluating 'scope.awesomeThings')
at client/test/modules/about/controllers/about.ctrl.js:21
Jeżeli ustawić LogLevel: LOG_DEBUG, About pliki * pokazują:
->% grep o /tmp/karma-debug.log
client/app/modules/about/app.about.js
client/app/modules/about/controllers/about.config.js
client/app/modules/about/controllers/about.controller.js
client/app/modules/about/controllers/about.routes.js
client/test/modules/about/controllers/about.ctrl.js
DEBUG [web-server]: serving (cached): client/app/modules/about/app.about.js
DEBUG [web-server]: serving (cached): client/app/modules/about/controllers/about.config.js
DEBUG [web-server]: serving (cached): client/app/modules/about/controllers/about.controller.js
DEBUG [web-server]: serving (cached): client/app/modules/about/controllers/about.routes.js
DEBUG [web-server]: serving (cached): client/test/modules/about/controllers/about.ctrl.js
Wiem, że brakuje czegoś podstawowego, ale mogę Zdaje się, że co znajduje.
Czy sprawdziłeś, czy rzeczy, które mówią, są niezdefiniowane, czy są zdefiniowane, czy nie? – Transcendence
Zdecydowanie zdefiniowane. Jeśli dodaję go do widoku, pojawi się. –