$ timeout.flush TypeError: Cannot read property '$$ nextSibling' from undefined

I have a segment of code inside $ timeout that fulfills a promise. When I write a unit test, I use $ timeout.flush () for that and I can step into the $ timeout block. The promise is then resolved (since $ timeout calls $ scope. $ Apply () internally), but then, after the method code ends and bubbles to jasmine, I get a TypeError: Can't read property "$$ nextSibling" from undefined. Has anyone else experienced this before?

Controller code:

$scope.timeoutFunction = function(){
    $timeout(function () {
        $scope.callFunction().then(function () {
            callAnotherFunction();
        });
    }, 0);
}

      

Unit test code:

$scope.timeoutFunction();

scope.$digest(); // not needed

$timeout.flush(); // even tried $timeout.flush(0);

      

Also if I mock the timeout as a callback function it works. Example:

function mockedTimeout() {
    arguments[0]();
}

$timeout = mockedTimeout;

      

Then we just use $ scope. $ digest for invoked promises, timeout starts immediately. Could this be an angular bug?

Full error stack:

TypeError: Cannot read property '$$nextSibling' of undefined
at n.$get.n.$digest (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\Libs\Angular\angular.min.js:124:101)
at n.$get.n.$apply (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\Libs\Angular\angular.min.js:126:293)
at Object.fn (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\Libs\Angular\angular.min.js:139:3)
at Function.angular.mock.$Browser.self.defer.flush (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\TDD\angular-mocks.js:127:42)
at Function.angular.mock.$TimeoutDecorator.$delegate.flush (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\TDD\angular-mocks.js:1732:28)
at null.<anonymous> (http://localhost:51679/Tests.js:254:18)
at jasmine.Block.execute (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\jasmine.js:1064:17)
at jasmine.Queue.next_ (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\jasmine.js:2096:31)
at jasmine.Queue.start (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\jasmine.js:2049:8)
at jasmine.Spec.execute (http://localhost:51679/referenceFile?path=D:\development\Projects\WebSite\Scripts\jasmine.js:2376:14)"

      

+3


source to share





All Articles