加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – angular / jasmine:错误:没有要刷新的延迟任务

发布时间:2020-12-17 17:14:21 所属栏目:安全 来源:网络整理
导读:我正在测试我的一个指令,我得到以下错误 Error: No deferred tasks to be flushed 我需要测试的代码是在$timeout内 $timeout(function () { $window.doStuff();}); 因此,当我想检查doStuff是否被调用时,我做了 $timeout.flush();expect($window.doStuff).toH
我正在测试我的一个指令,我得到以下错误

Error: No deferred tasks to be flushed

我需要测试的代码是在$timeout内

$timeout(function () {
    $window.doStuff();
});

因此,当我想检查doStuff是否被调用时,我做了

$timeout.flush();
expect($window.doStuff).toHaveBeenCalled();

但是,现在我需要测试一种我不希望调用doStuff的情况.所以我做了:

$timeout.flush();
expect($window.doStuff).not.toHaveBeenCalled(); // Notice the not here!!

但是,因为没有调用$timeout,$timeout.flush()给了我这个错误.

所以问题是,测试这种情况的首选方法是什么?

解决方法

使用$timeout.verifyNoPendingTasks()检查是否没有添加任务.

检查角度文档here:

Verifies that there are no pending tasks that need to be flushed.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读