nativescript-angular icon indicating copy to clipboard operation
nativescript-angular copied to clipboard

ComponentFixture.whenStable() doesn't work

Open stewx opened this issue 5 years ago • 2 comments

Environment

  • CLI: 6.2.2
  • Cross-platform modules:
  • Android Runtime:
  • iOS Runtime:
  • Plugin(s):
  • NativeScript-Angular: 8.20.4
  • Angular: 8.2.14

Describe the bug

Using whenStable() to test asynchronous functionality does not work as expected.

To Reproduce

Component code:

    onTapButton() {
        const delay = 2000;
        setTimeout(() => {
            this.buttonWasTapped = true;
        }, delay)
    }

Unit test code:

  it('should mark the button as pushed after 2 seconds when you tap it (using whenStable)', async(() => {
    fixture.detectChanges();
    component.onTapButton();

    fixture.detectChanges();

    fixture.whenStable().then(() => {
        expect(component.buttonWasTapped).toBe(true);
    });
  }));

Expected behavior The test passes, because whenStable().then() waits for the async tasks to complete.

Sample project

Minimal reproduction: https://github.com/stewx/nativescript-async-bug-demo

Additional context

stewx avatar Feb 14 '20 13:02 stewx

@stewx the issue is indeed a bug - it is probably related to this comment.

NickIliev avatar Mar 09 '20 13:03 NickIliev

This is a serious issue and has sat here for over a year with no action. No one can seriously use NativeScript without the ability to write unit tests.

stewx avatar Apr 12 '21 18:04 stewx