Open TrevorKarjanis opened 3 months ago
I took an innovation sprint to investigate this and other related asynchronous testing issues. I created a repository, Angular Asynchronous Test Specification, which contains a test specification, async.spec.ts, of various asynchronous testing scenarios including micro and macrotasks, RxJS, and Nimble components. I reproduced and cataloged the issue described in this bug report and a few others which I have copied to outline here. In conclusion, I updated the async testing guidelines.
fakeAsync
may not work with even simple asynchronous Nimble updates like button appearance.- Nimble's
waitForUpdatesAsync
has two common issues.
- In watch mode,
waitForUpdatesAsync
may timeout after a change and compile. Refresh the page to rerun the test.- non-fakeAsync tests can leak tasks that break calls to
waitForUpdatesAsync
for all subsequent tests.- There have been a few reported cases where
ComponentFixture.whenStable
did not work andwaitForUpdatesAsync
was required for components with a menu and select. However, the exact reason is not known.
π Bug Report
Tests timeout in a specific test suite, but not others, because
waitForUpdatesAsync
hangs.waitForUpdatesAsync
hangs, because fast-element@1.12.0DOM.nextUpdate
adds tasks but does not process tasks if they already exist. All subsequent tests that usewaitForUpdatesAsync
fail.The Nimble documentation states that
processUpdates
should be called inafterEach
forfakeAsync
tests but notwaitForAsync
tests. There are otherwaitForAsync
test suites in the same workspace that usewaitForUpdatesAsync
andComponentFixture.whenStable
that do not fail.waitForUpdatesAsync
seems to only be needed for certain components, like menus and selects. Otherwise,whenStable
updates Nimble components without issue.π» Repro or Code Sample
Replace
processUpdates
withwaitForUpdatesAsync
in the workspace members test suite. The original commit was 199bf0. See Current Behavior for the error logs.π€ Expected Behavior
Either calling
processUpdates
fromafterEach
should be required for asynchronous tests orwaitForUpdatesAsync
should process tasks when tasks already exist. The former expectation is problematic, because it is not a requirement of many tests.π― Current Behavior
The test and subsequent tests that use
waitForUpdatesAsync
timeout.π Possible Solution
processUpdates
at the correct times instead ofwaitForUpdatesAsync
, but this wouldn't fixwaitForUpdatesAsync
.processUpdates
would be required in addition towaitForUpdatesAsync
for components that requirewaitForUpdatesAsync
.processUpdates
inafterEach
, and update the documentation.π¦ Context
I migrated the security application to use Nimble components. The view whose test suite was affected by this issue includes
nimble-button
,nimble-icon-*
, andnimble-menu-button
. It used to includenimble-select
.π Your Environment