$q doesn't remove pending tasks in angular

119 views Asked by At

If I create a test for angular where I use $q to mock or create a promise then a defer task is created.

I thought that by calling $rootScope.$apply should resolve these promises.

But if I do this then call $timeout.verifyNoPendingTasks() an exception is thrown because

Error: Deferred tasks to flush (1): {id: 0, time: 0}

Why is this and how to fix it ?

 it.only('should work', function () {
        var spy = sinon.spy();
        $q.when().then(spy);
        $rootScope.$apply();
        spy.should.have.been.called;

        $timeout.verifyNoPendingTasks();
    });
0

There are 0 answers