Skip to content

Commit e208bc1

Browse files
committed
refactor(cdk/testing): reuse stabilize callback when creating test element
Any time we were creating a new test element, we were giving it a new stabilization callback. These changes reuse the same one between all elements in order to reduce the amount of memory for each element.
1 parent 97ec228 commit e208bc1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/cdk/testing/selenium-webdriver/selenium-web-driver-harness-environment.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export class SeleniumWebDriverHarnessEnvironment extends HarnessEnvironment<
7474
/** The options for this environment. */
7575
private _options: WebDriverHarnessEnvironmentOptions;
7676

77+
/** Environment stabilization callback passed to the created test elements. */
78+
private _stabilizeCallback = () => this.forceStabilize();
79+
7780
protected constructor(
7881
rawRootElement: () => webdriver.WebElement,
7982
options?: WebDriverHarnessEnvironmentOptions,
@@ -123,7 +126,7 @@ export class SeleniumWebDriverHarnessEnvironment extends HarnessEnvironment<
123126

124127
/** Creates a `TestElement` from a raw element. */
125128
protected createTestElement(element: () => webdriver.WebElement): TestElement {
126-
return new SeleniumWebDriverElement(element, () => this.forceStabilize());
129+
return new SeleniumWebDriverElement(element, this._stabilizeCallback);
127130
}
128131

129132
/** Creates a `HarnessLoader` rooted at the given raw element. */

src/cdk/testing/testbed/testbed-harness-environment.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
9696
/** The options for this environment. */
9797
private _options: TestbedHarnessEnvironmentOptions;
9898

99+
/** Environment stabilization callback passed to the created test elements. */
100+
private _stabilizeCallback = () => this.forceStabilize();
101+
99102
protected constructor(
100103
rawRootElement: Element,
101104
private _fixture: ComponentFixture<unknown>,
@@ -198,7 +201,7 @@ export class TestbedHarnessEnvironment extends HarnessEnvironment<Element> {
198201

199202
/** Creates a `TestElement` from a raw element. */
200203
protected createTestElement(element: Element): TestElement {
201-
return new UnitTestElement(element, () => this.forceStabilize());
204+
return new UnitTestElement(element, this._stabilizeCallback);
202205
}
203206

204207
/** Creates a `HarnessLoader` rooted at the given raw element. */

0 commit comments

Comments
 (0)