nativescript-angular
nativescript-angular copied to clipboard
ComponentFixture.whenStable() doesn't work
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 the issue is indeed a bug - it is probably related to this comment.
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.