Jasmine test for AngularJS $locationChangeSuccess
问题 How would I write a test for this following piece of code? $scope.$on('$locationChangeSuccess', function () { $(".modal-backdrop").removeClass('modal-backdrop'); }); 回答1: The following should work: beforeEach(function() { $('body').append('<div id="test" class="modal-backdrop"/>'); }); afterEach(function() { $('#test').remove(); }); it('should remove the classname on $locationChangeSuccess', function() { spyOn($scope, '$on').and.callThrough(); $scope.$broadcast('$locationChangeSuccess');