angularjs – jasmine:在由jasmine.DEFAULT_TIMEOUT_INTERVAL指
发布时间:2020-12-17 08:56:15 所属栏目:安全 来源:网络整理
导读:我有一个角服务叫做requestNotificationChannel: app.factory("requestNotificationChannel",function($rootScope) { var _DELETE_MESSAGE_ = "_DELETE_MESSAGE_"; function deleteMessage(id,index) { $rootScope.$broadcast(_DELETE_MESSAGE_,{ id: id,in
我有一个角服务叫做requestNotificationChannel:
app.factory("requestNotificationChannel",function($rootScope) { var _DELETE_MESSAGE_ = "_DELETE_MESSAGE_"; function deleteMessage(id,index) { $rootScope.$broadcast(_DELETE_MESSAGE_,{ id: id,index: index }); }; return { deleteMessage: deleteMessage }; }); 我试图使用茉莉花单元测试这项服务: "use strict"; describe("Request Notification Channel",function() { var requestNotificationChannel,rootScope,scope; beforeEach(function(_requestNotificationChannel_) { module("messageAppModule"); inject(function($injector,_requestNotificationChannel_) { rootScope = $injector.get("$rootScope"); scope = rootScope.$new(); requestNotificationChannel = _requestNotificationChannel_; }) spyOn(rootScope,'$broadcast'); }); it("should broadcast delete message notification",function(done) { requestNotificationChannel.deleteMessage(1,4); expect(rootScope.$broadcast).toHaveBeenCalledWith("_DELETE_MESSAGE_",{ id: 1,index: 4 }); done(); }); }); 我阅读关于Jasmine的异步支持,但因为我是新的单元测试与JavaScript不能使它的工作。 我收到一个错误: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL 和我的测试花了太长的时间(约5秒)。 有人可以帮助我提供我的代码的工作示例与一些解释?
在你的函数中有一个参数将导致它尝试异步调用。
//this block signature will trigger async behavior. it("should work",function(done){ //... }); //this block signature will run synchronously it("should work",function(){ //... }); 它没有区别什么做的参数命名,它的存在就是重要的。我从太多的副本/面食碰到这个问题。 Jasmin Asynchronous Support文档注意到,参数(上面做的命名)是一个回调,可以调用它来让Jasmine知道异步函数何时完成。如果你从不调用它,Jasmine永远不会知道你的测试是完成,并将最终超时。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angularjs – 你在Angular中存储/创建模型的位置?
- angularjs – Angular-material md-select with images或sv
- twitter-bootstrap – Bootstrap 4 Navbar即使在切换时也保
- Scala解释器有哪些限制和解决方法?
- angularjs 指令scope中“=”、“@”、“&”的区别
- 《数据结构》实验一
- 推荐Vim插件用于C编码?
- angular – 按服务中的键查询单个Firebase对象
- scala(包)对象被反编译为java – 包含“new();”的静态初始
- angularjs – 将响应下载为excel文件