पर मैं निर्देश से $ emit पर जासूसी करने की कोशिश कर रहा हूं, लेकिन किसी भी तरह से मैं $ emit 'सुन' को जासूसी नहीं कर सकता।
यह मेरा निर्देशों में कोड है 'नियंत्रक:
$scope.$on('send', function() {
console.log('called');
$scope.$emit('resultSend', {'ok': true, 'data': ''});
});
यह मेरा इकाई परीक्षण है:
var $rootScope, $compile, elm, element;
beforeEach(inject(function ($injector) {
$rootScope = $injector.get('$rootScope');
$compile = $injector.get('$compile');
elm = angular.element('<test></test>');
element = $compile(elm)($rootScope);
}));
it('should listen for the send broadcast and emit the resultSend', function() {
spyOn($rootScope, '$emit');
$rootScope.$broadcast('send');
expect($rootScope.$emit).toHaveBeenCalledWith('resultSend');
});
console.log निर्गम (' कहा जाता है ') कर्मा द्वारा मुद्रित किया जाता है, तो मुझे लगता है कि यूनिट टेस्ट प्रसारण कार्यक्रम काम करता है।
क्या इसे $ emit के साथ प्रसारण करना नहीं है, लेकिन यदि ऐसा है, तो मैं इसे कैसे पकड़ूं, और यदि नहीं, तो मैं इस मामले को और कैसे संभाल सकता हूं?
आप '$ रूटस्कोप 'पर जासूसी कर रहे हैं और' $ स्कोप 'पर' $ emit' को कॉल कर रहे हैं। –