{"record":{"id":"30bb18970af9d79d","repo":"angular/angular.js","slug":"no-pending-animations-ready-to-be-closed-or-flushe","errorCode":null,"errorMessage":"No pending animations ready to be closed or flushed","messagePattern":"No pending animations ready to be closed or flushed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ngMock/angular-mocks.js","lineNumber":1033,"sourceCode":"        flush: function(hideErrors) {\n          $rootScope.$digest();\n\n          var doNextRun, somethingFlushed = false;\n          do {\n            doNextRun = false;\n\n            if ($$rAF.queue.length) {\n              $$rAF.flush();\n              doNextRun = somethingFlushed = true;\n            }\n\n            if ($$animateAsyncRun.flush()) {\n              doNextRun = somethingFlushed = true;\n            }\n          } while (doNextRun);\n\n          if (!somethingFlushed && !hideErrors) {\n            throw new Error('No pending animations ready to be closed or flushed');\n          }\n\n          $rootScope.$digest();\n        }\n      };\n\n      angular.forEach(\n        ['animate','enter','leave','move','addClass','removeClass','setClass'], function(method) {\n        animate[method] = function() {\n          animate.queue.push({\n            event: method,\n            element: arguments[0],\n            options: arguments[arguments.length - 1],\n            args: arguments\n          });\n          return $delegate[method].apply($delegate, arguments);\n        };\n      });","sourceCodeStart":1015,"sourceCodeEnd":1051,"githubUrl":"https://github.com/angular/angular.js/blob/d8f77817eb5c98dec5317bc3756d1ea1812bcfbe/src/ngMock/angular-mocks.js#L1015-L1051","documentation":"ngMock's mock $animate queues element animations; its flush() closes everything queued by repeatedly draining $$rAF and $$animateAsyncRun queues (looping until a pass flushes nothing) and finishes with a $digest. If a full pass flushes nothing and hideErrors is falsy, there was no queued animation work, so flush() throws 'No pending animations ready to be closed or flushed'.","triggerScenarios":"Calling $animate.flush() before any $animate operation (animate/enter/leave/move/addClass/removeClass/setClass) has queued work; calling flush after a previous flush already drained the queues; the animation was disabled ($animate.enabled(false)) or the element/class change never happened, so nothing queued.","commonSituations":"Testing a directive whose $animate.addClass only runs when a scope condition is true, but the test never made the condition true; the code path triggering the animation sits inside a $timeout or event handler that has not run yet; passing flush(true) suppresses the throw (hideErrors), which hides both the error and any assumption mistake.","solutions":["Trigger the DOM/class change that queues the animation (run the scope/digest path that calls $animate) before calling $animate.flush().","Guard the flush: only call it when $animate.queue.length > 0 or $$rAF.queue.length > 0.","If an empty queue is legitimate in the test's flow, call $animate.flush(true) to skip the throw — but then you are only paying for the closing $digest."],"exampleFix":"// before\nit('adds .highlight', inject(function($animate, $rootScope) {\n  $rootScope.$apply('vm.active = false'); // condition false: nothing queued\n  $animate.flush(); // throws\n}));\n\n// after\nit('adds .highlight', inject(function($animate, $rootScope) {\n  $rootScope.$apply('vm.active = true'); // directive queues addClass\n  $animate.flush();\n}));","handlingStrategy":"validation","validationCode":"// Only flush when animation work is actually queued\ninject(function($animate) {\n  if ($animate.queue.length > 0) {\n    $animate.flush();\n  }\n});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make the scope/class change that queues the animation before flushing.","Check $animate.enabled(false) is not set globally in the test module.","Use $animate.flush(true) only when an empty queue is a legitimate outcome."],"tags":["angular-mocks","animation","flush","testing"],"backgroundTag":"empty-flush-queue","analyzedSha":"d8f77817eb5c98dec5317bc3756d1ea1812bcfbe","analyzedAt":"2026-08-21T20:36:31.651Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}