Skip to content

Commit

Permalink
fix(material-experimental): avoid error when trying to use harness af…
Browse files Browse the repository at this point in the history
…ter fixture is destroyed

Currently before most operations in the harnesses we call `fixture.detectChange`, however doing so on a destroyed fixture throws a vague error. These changes avoid detecting changes on destroyed fixtures.
  • Loading branch information
crisbeto committed Sep 11, 2019
1 parent 31d8819 commit c04a1d0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cdk/testing/testbed/testbed-harness-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import {UnitTestElement} from './unit-test-element';

/** A `HarnessEnvironment` implementation for Angular's Testbed. */
export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
private _destroyed = false;

constructor(rawRootElement: Element, private _fixture: ComponentFixture<unknown>) {
super(rawRootElement);
_fixture.componentRef.onDestroy(() => this._destroyed = true);
}

/** Creates a `HarnessLoader` rooted at the given fixture's root element. */
Expand Down Expand Up @@ -54,7 +57,9 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
}

private async _stabilize(): Promise<void> {
this._fixture.detectChanges();
await this._fixture.whenStable();
if (!this._destroyed) {
this._fixture.detectChanges();
await this._fixture.whenStable();
}
}
}

0 comments on commit c04a1d0

Please sign in to comment.