components icon indicating copy to clipboard operation
components copied to clipboard

Ripple effect on button causes fakeAsync component tests to fail

Open Uniqen opened this issue 9 years ago • 9 comments

Bug, feature request, or proposal:

Bug: Ripple effect on button causes fakeAsync component test to fail with the message: " Error: 1 timer(s) still in the queue."

What is the expected behavior?

The test to pass without any error.

What is the current behavior?

The test fail with the following message: Error: 1 timer(s) still in the queue. at new Error (native) at webpack:///app/~/@angular/core/bundles/core-testing.umd.js:353:0 <- src/test.ts:6646:27 [ProxyZone] at TestBed.execute (webpack:///app/~/@angular/core/bundles/core-testing.umd.js:820:0 <- src/test.ts:7113:23) [ProxyZone] at Object. (webpack:///app/~/@angular/core/bundles/core-testing.umd.js:907:32 <- src/test.ts:7200:49) [ProxyZone] at ProxyZoneSpec.onInvoke (webpack:///app/~/zone.js/dist/proxy.js:79:0 <- src/test.ts:62427:39) [ProxyZone] at Zone.run (webpack:///app/~/zone.js/dist/zone.js:113:0 <- src/test.ts:100503:43) [ProxyZone => ProxyZone] at Object. (webpack:///app/~/zone.js/dist/jasmine-patch.js:102:0 <- src/test.ts:62142:34) [ProxyZone] at webpack:///app/~/@angular/core/bundles/core-testing.umd.js:91:0 <- src/test.ts:6384:21 [ProxyZone]

What are the steps to reproduce?

FooComponent template with button i.e. <button md-raised-button>Foo</button> And component test: `beforeEach(async(() => { fixture = TestBed.createComponent(FooComponent); } fit('test failing', fakeAsync(() => { fixture.debugElement.query(By.css('button')).nativeElement.click(); fixture.detectChanges(); tick(); }));

The test succeeds when adding disableRipple to the button.

What is the use-case or motivation for changing an existing behavior?

Hard to write component tests in 2.0.0-alpha.11-2.

Which versions of Angular, Material, OS, browsers are affected?

Introduced in 2.0.0-alpha.11-2, was working in 2.0.0-alpha.10. Using angular 2.2.4.

Is there anything else we should know?

Uniqen avatar Dec 09 '16 20:12 Uniqen

@crisbeto can you reproduce this?

jelbourn avatar Dec 09 '16 22:12 jelbourn

The same test works for me @Uniqen. Are you sure there isn't something else that is triggering a timeout? Here's my full setup:

import {Component} from '@angular/core';
import {async, TestBed, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';

fdescribe('foo', () => {
  let fixture: ComponentFixture<FooComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [FooComponent]
    });

    TestBed.compileComponents();
    fixture = TestBed.createComponent(FooComponent);
  }));

  it('test failing', fakeAsync(() => {
    fixture.debugElement.query(By.css('button')).nativeElement.click();
    fixture.detectChanges();
    tick();
  }));
});

@Component({ template: '<button md-raised-button>Foo</button>' })
export class FooComponent {}

crisbeto avatar Dec 10 '16 10:12 crisbeto

When I add fixture.detectChanges(); before the click I get the "Error: 1 timer(s) still in the queue." error.

Uniqen avatar Dec 11 '16 14:12 Uniqen

Weird since I don't get it. Neither when adding it inside the test itself, nor when I put it in the beforeEach.

crisbeto avatar Dec 11 '16 14:12 crisbeto

I've located the difference in our tests:

            imports: [
                MaterialModule.forRoot(),
            ]

In my test the before each is:

TestBed.configureTestingModule({
            declarations: [FooComponent],
            imports: [
                MaterialModule.forRoot(),
            ]
        }).compileComponents();

Isn't that required to include Material directives in the test?

Uniqen avatar Dec 12 '16 19:12 Uniqen

You're probably right, I'll re-check it.

crisbeto avatar Dec 12 '16 19:12 crisbeto

AFAICT this is no longer an issue

import {Component} from '@angular/core';
import {async, TestBed, ComponentFixture, fakeAsync, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {MdButtonModule} from '@angular/material';

fdescribe('foo', () => {
  let fixture: ComponentFixture<FooComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [FooComponent],
      imports: [
        MdButtonModule
      ]
    });

    TestBed.compileComponents();
    fixture = TestBed.createComponent(FooComponent);
  }));

  it('test failing', fakeAsync(() => {
    fixture.debugElement.query(By.css('button')).nativeElement.click();
    fixture.detectChanges();
    tick();
  }));
});

@Component({ template: '<button md-raised-button>Foo</button>' })
export class FooComponent {}

willshowell avatar Jun 09 '17 15:06 willshowell

Okay, thanks!

jelbourn avatar Jun 09 '17 16:06 jelbourn

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.