Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs $timeout.flush()不工作_Angularjs_Karma Jasmine - Fatal编程技术网

Angularjs $timeout.flush()不工作

Angularjs $timeout.flush()不工作,angularjs,karma-jasmine,Angularjs,Karma Jasmine,我试图在$timeout之后测试更改,如下所示: it('after timeout', function () { expect(scope.Vm.isLoaded).toBe(true); $timeout.flush(10); $timeout.flush(2000); $timeout.verifyNoPendingTasks(); expect(scope.Vm.isLoaded).toBe(false);

我试图在
$timeout
之后测试更改,如下所示:

it('after timeout', function () {
        expect(scope.Vm.isLoaded).toBe(true);
        $timeout.flush(10);
        $timeout.flush(2000);
        $timeout.verifyNoPendingTasks();
        expect(scope.Vm.isLoaded).toBe(false);
      });
这不起作用 检查
$timeout.verifyNoPendingTasks()时
我有一个错误:

错误:要刷新的延迟任务(2):{id:0,时间:0},{id:1,时间: 2000}

然后我补充说:

$timeout.flush(10);
结果是:

错误:要刷新的延迟任务(1):{id:1,时间:2000}

添加时:

$timeout.flush(10);
$timeout.flush(2000);

测试失败了,看起来它不工作了,我错过了什么?有什么想法吗

很难帮助您,因为一开始您没有显示要测试的代码。我们不知道为什么您的测试代码有两次超时

第二个问题是Angular JS在verifyNoPendingTasks()方面存在问题,如中所述

在您创建此问题后,它在6月27日的提交中得到了解决


因此,我相信如果你更新AngularJS依赖项,你可以得到正确的$verifyNoPendingTasks方法。

尝试这个链接@Kasiriveni,谢谢,我使用几乎相同的方法,除了,我没有使用
sumWithWait
函数,而是使用
$rootScope.$on
事件,并在itI内部运行timeout use$rootScope.$digest()$timeout.flush();你能添加你要测试的部分吗?