Open
Description
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