Bir Yeoman (1.0RC1) iskele Açısal (1.0.7) uygulamasında grunt test
çalıştırırken, alıyorum aşağıdaki hata:
TypeError: 'undefined' is not a function (evaluating '$scope.$parent.userLoggedIn(true)')
userLoggedIn()
bir ana kontrol index.js
içindedir. Fonksiyonun kendisi açısal uygulama içinde iyi çalışır.
Bu hata, denetleyicideki diğer $scope.$parent
boole veya dizge değişkenlerinde oluşmaz, bu nedenle bir üst öğedeki arama işlevleri doğrudan ilişkilidir.
Ben de $scope.$parent
yanlış şekilde kullanıyorum o ya ben testinde benim index.js
denetleyicisi tanımlamak gerektiğini, ancak bilmek zor bu yüzden Karma test belgeleri, sporadik olduğu düşünüyorum.
DÜZENLEME: İşte
'use strict';
angular.module('uiApp')
.controller('LookupCtrl', ['$scope', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
$scope.$parent.userLoggedIn(true);
}]);
testi edilmektedir:.
'use strict';
describe('Controller: LookupCtrl', function() {
// load the controller's module
beforeEach(module('uiApp'));
var LookupCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
LookupCtrl = $controller('LookupCtrl', {
$scope: scope
});
}));
it('should attach a list of awesomeThings to the scope', function() {
expect(scope.awesomeThings.length).toBe(3);
});
});
(Evet ben sadece şimdilik varsayılan awesomeThings
testi kullanılarak biliyorum ben yeniyim İşte kontrolcüsüdür Açısal test için).
Kodunuzu test denetleyicisine verebilir misiniz? – BKM
Genel olarak, bir işlevi bulmak için özellik adı kullanmaya çalıştığınız, ancak birlikte çalıştığınız nesnenin böyle bir özelliği olmadığı anlamına gelir. Böylece, 'undefined' işlevini bir işlev olarak kullanmaya çalışıyorsunuz ve bu bir işlev değil. – Pointy