title: Angular/Karma unit test error "1 timer(s) still in the queue"
body: <p>This is hardly first encounter I've had with <code>"1 timer(s) still in the queue"</code>, but usually I find some way to use <code>tick()</code> or <code>detectChanges()</code>, etc., to get out of it.</p>
  
  <p>The test below was working fine until I tried to test for a condition that I know should throw an exception:</p>
  
  <pre><code>  it('should be able to change case', fakeAsync(() =&gt; {
      expect(component).toBeTruthy();
  
      fixture.whenStable().then(fakeAsync(() =&gt; {
        component.case = 'lower';
        fixture.autoDetectChanges();
        tick(500);
        const input = fixture.nativeElement.querySelector('input') as HTMLInputElement;
        typeInElement('abcDEF', input);
        fixture.autoDetectChanges();
        tick(500);
        expect(component.text).toEqual('abcdef');
  
        component.case = 'upper';
        fixture.autoDetectChanges();
        tick(500);
        typeInElement('abcDEF', input);
        fixture.autoDetectChanges();
        tick(500);
        expect(component.text).toEqual('ABCDEF');
  
        // Everything above works fine. Here's where the trouble begins
        expect(() =&gt; {
          component.case = 'foo';
          fixture.autoDetectChanges();
          tick(500);
        }).toThrowError(/Invalid case attribute/);
      }));
    }));
  </code></pre>
  
  <p>What I'm testing is an Angular component that's a wrapper around a Material input field. The component has many optional attributes, most of them just pass-through attributes for common input field features, but a few custom attributes too, like the one I'm testing above for upper-/lowercase conversion.</p>
  
  <p>The acceptable values for the <code>case</code> attribute are <code>upper</code>, <code>lower</code>, and <code>mixed</code> (with empty string, null, or undefined treated as <code>mixed</code>). The component should throw an exception for anything else. Apparently it does, and the test succeeds, but along with the success I get:</p>
  
  <pre><code>ERROR: 'Unhandled Promise rejection:', '1 timer(s) still in the queue.', '; Zone:', 'ProxyZone', '; Task:', 'Promise.then', '; Value:', Error: 1 timer(s) still in the queue.
  Error: 1 timer(s) still in the queue.
     ...
  </code></pre>
  
  <p>Can anyone tell me what I might be doing wrong, or a good way to flush out lingering timers?</p>
  
  <p>Disclaimer: A big problem when I go looking for help with Karma unit tests is that, even when I explicitly search for "karma", I mostly find answers for Pr0tractor, Pr0tractor, and more Pr0tractor. This isn't Pr0tractor! (Deliberately misspelled with a zero so it doesn't get search matches.)</p>
  
  <p>UPDATE: I can work around my problem like this:</p>
  
  <pre><code>      expect(() =&gt; {
          component.inputComp.case = 'foo';
        }).toThrowError(/Invalid camp-input case attribute/);
  </code></pre>
  
  <p>This isn't as good of a test as assigning the (bad) value via an HTML attribute in the test component's template, because I'm just forcing the value directly into the component's setter for the attribute itself, but it'll do until I have a better solution.</p>