मैं नियंत्रक में अपने कार्यक्रमों के लिए यूनिट परीक्षण लिखने की कोशिश कर रहा हूं।
नीचे मेरी नियंत्रक
myApp.controller('ParentCtrl', ['$scope', function ($scope) {
$scope.message = "Some text in parent";
$scope.$on("update_parent_controller", function(event, message){
$scope.message = message;
});
}])
.controller('ChildCtrl', ['$scope', function ($scope) {
$scope.clickFunction = function() {
$scope.message = "Parent updated from child controller";
$scope.$emit('update_parent_controller', $scope.message);
}
}]);
है और नीचे अपने परीक्षण है कि मैं
describe("Hello Controller Test", function() {
var ctrl, scope;
beforeEach(module("myApp"));
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
spyOn(scope, '$on');
ctrl = $controller("ParentCtrl", {
$scope : scope
});
}));
it('should change ParentCtrl message property from child ctrl', function(){
var new_hero = 'Ralf ninja turtle',
sub_scope = scope.$new();
sub_scope.$emit('update_parent_controller', new_hero);
expect(scope.$on).toHaveBeenCalled();
expect(scope.message).toBe('Ralf ninja turtle'); //Getting err here
});
});
मैं माता पिता के नियंत्रक में संदेश की आशा कर रहा हूँ अद्यतन करने की, लिखने की कोशिश कर रहा हूँ लेकिन परीक्षा है उम्मीद में विफल (स्कोप.मेसेज)। टोबी ('राल्फ निंजा कछुए');