且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在AngularJS茉莉花单元测试用例$ routeChangeStart

更新时间:2023-02-17 07:44:41

这是运行块运行的每个模块被加载时,使监听器在测试期间被注册。你只需要该事件实际被发送,这样就可以在它测试code。这样的事情应该做的伎俩:

That run block runs every time the module is loaded, so that listener is being registered during the tests. You just need that event to actually be sent so that you can test the code within it. Something like this should do the trick:

it("should test the $routeChangeStart listener", inject(function($rootScope) {
   $rootScope.$broadcast("$routeChangeStart");
   //expects for the listener
}));

请参阅What是测试事件的角度,***的办法?了解如何在通用测试活动。

See What is the best approach to test events in angular? for how to test events in general.