All my component unit tests that are exercising Material components that make use of OverlayRef, like mat-select throw an error when my unit test destroys the test fixture due to a setTimeout(500) in OverlayRef.detachBackdrop:
It would be really awesome if OverlayRef.ngOnDestory this timeout would be cleared with clearTimeout(timeoutId).
Currently the only workarounds is to call tick(500) at the end of my unit tests. I don't like this because it artificially delays all my unit tests.
It does get cleared (see https://github.com/angular/material2/blob/5321ab3cc4104369ea756857210c724f6c028cea/src/cdk/overlay/overlay-ref.ts#L416), however that callback depends on a transitionend event being fired on the backdrop which won't happen on its own during a unit test.
Closing since this behavior is unlikely to change.
Explicitly calling fixture.destroy() at the end of unit tests causes the overlay-ref to close the backdrop, but it schedules a new task in zonejs: https://github.com/angular/material2/blob/5321ab3cc4104369ea756857210c724f6c028cea/src/cdk/overlay/overlay-ref.ts#L436
To workaround this issue I have been able to do the following at the end of each test:
fixture.destroy();
flush();
By calling flush() the Scheduler of the FakeAsyncTestZoneSpec has it's non-periodic tasks flushed, leaving no tasks in the scheduler's queue.
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._
Most helpful comment
Explicitly calling
fixture.destroy()at the end of unit tests causes the overlay-ref to close the backdrop, but it schedules a new task in zonejs: https://github.com/angular/material2/blob/5321ab3cc4104369ea756857210c724f6c028cea/src/cdk/overlay/overlay-ref.ts#L436To workaround this issue I have been able to do the following at the end of each test:
By calling
flush()theSchedulerof theFakeAsyncTestZoneSpechas it's non-periodic tasks flushed, leaving no tasks in the scheduler's queue.