Thi*_*ibs 1 jasmine angularjs angularjs-scope karma-runner
我有控制器监听destroy事件,我无法弄清楚如何测试这个事件.
有谁知道怎么测试毁灭?
在控制器中:
$scope.$on('$destroy', function () {
//does something
});
Run Code Online (Sandbox Code Playgroud)
在测试中:
beforeEach(inject(function ($rootScope, $injector) {
rootScope = $injector.get('$rootScope');
scope = $rootScope;
}));
it('should do something when scope $destroyed', function () {
//how to trigger the destroy event listened for in controller?
expect(somefunction).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
谢谢
我没有尝试过,但范围有一个功能$destroy().在执行断言之前调用它.
it('should do something when scope $destroyed', function () {
//how to trigger the destroy event listened for in controller?
scope.$destroy(); // created somewhere before each test
expect(somefunction).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3064 次 |
| 最近记录: |