title: angular/jasmine: Error: No deferred tasks to be flushed
body: <p>I'm unit testing one of my directives and I get the following error</p>
  
  <pre><code>Error: No deferred tasks to be flushed
  </code></pre>
  
  <p>The code I need to test is inside a $timeout</p>
  
  <pre><code>$timeout(function () {
      $window.doStuff();
  });
  </code></pre>
  
  <p>So when I want to check if <code>doStuff</code> was called I do</p>
  
  <pre><code>$timeout.flush();
  expect($window.doStuff).toHaveBeenCalled();
  </code></pre>
  
  <p>However, now I need to test a situation in which I don't expect <code>doStuff</code> to have been called. So I did:</p>
  
  <pre><code>$timeout.flush();
  expect($window.doStuff).not.toHaveBeenCalled(); // Notice the not here!!
  </code></pre>
  
  <p>However, because <code>$timeout</code> was not called, the <code>$timeout.flush()</code> gives me this error. </p>
  
  <p>So the question is, what is the preferred way to test this situation ?</p>