Skip to content

Commit 69fb161

Browse files
JeanMechemattrbeck
authored andcommitted
refactor(core): remove checkNoChanges from the public API.
It's an internal API. BREAKING CHANGE: `ChangeDetectorRef.checkNoChanges` was removed. In tests use `fixture.detectChanges()` instead.
1 parent 75560ce commit 69fb161

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

goldens/public-api/core/index.api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ export enum ChangeDetectionStrategy {
218218

219219
// @public
220220
export abstract class ChangeDetectorRef {
221-
// @deprecated
222-
abstract checkNoChanges(): void;
223221
abstract detach(): void;
224222
abstract detectChanges(): void;
225223
abstract markForCheck(): void;

packages/core/src/change_detection/change_detector_ref.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,6 @@ export abstract class ChangeDetectorRef {
9797
*/
9898
abstract detectChanges(): void;
9999

100-
/**
101-
* Checks the change detector and its children, and throws if any changes are detected.
102-
*
103-
* Use in development mode to verify that running change detection doesn't introduce
104-
* other changes. Calling it in production mode is a noop.
105-
*
106-
* @deprecated This is a test-only API that does not have a place in production interface.
107-
* `checkNoChanges` is already part of an `ApplicationRef` tick when the app is running in dev
108-
* mode. For more granular `checkNoChanges` validation, use `ComponentFixture`.
109-
*/
110-
abstract checkNoChanges(): void;
111-
112100
/**
113101
* Re-attaches the previously detached view to the change detection tree.
114102
* Views are attached to the tree by default.

packages/core/test/acceptance/change_detection_spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
EventEmitter,
2424
inject,
2525
Input,
26+
ɵViewRef as InternalViewRef,
2627
OnInit,
2728
Output,
2829
provideCheckNoChangesConfig,
@@ -1398,7 +1399,7 @@ describe('change detection', () => {
13981399
const fixture = TestBed.createComponent(NoChangesComp);
13991400

14001401
expect(() => {
1401-
fixture.componentInstance.cdr.checkNoChanges();
1402+
(fixture.componentInstance.cdr as InternalViewRef<unknown>).checkNoChanges();
14021403
}).toThrowError(
14031404
/ExpressionChangedAfterItHasBeenCheckedError: .+ Previous value: '.*undefined'. Current value: '.*1'/gi,
14041405
);
@@ -1411,7 +1412,9 @@ describe('change detection', () => {
14111412
});
14121413
const fixture = TestBed.createComponent(AppComp);
14131414

1414-
expect(() => fixture.componentInstance.cdr.checkNoChanges()).toThrowError(
1415+
expect(() =>
1416+
(fixture.componentInstance.cdr as InternalViewRef<unknown>).checkNoChanges(),
1417+
).toThrowError(
14151418
/ExpressionChangedAfterItHasBeenCheckedError: .+ Previous value: '.*undefined'. Current value: '.*1'/gi,
14161419
);
14171420
});
@@ -1433,7 +1436,9 @@ describe('change detection', () => {
14331436
});
14341437
const fixture = TestBed.createComponent(EmbeddedViewApp);
14351438

1436-
expect(() => fixture.componentInstance.cdr.checkNoChanges()).toThrowError(
1439+
expect(() =>
1440+
(fixture.componentInstance.cdr as InternalViewRef<unknown>).checkNoChanges(),
1441+
).toThrowError(
14371442
/ExpressionChangedAfterItHasBeenCheckedError: .+ Previous value: '.*undefined'. Current value: '.*true'/gi,
14381443
);
14391444
});
@@ -1452,7 +1457,9 @@ describe('change detection', () => {
14521457
expect(comp.viewCheckCount).toEqual(1);
14531458

14541459
comp.value = 2;
1455-
expect(() => fixture.componentInstance.cdr.checkNoChanges()).toThrow();
1460+
expect(() =>
1461+
(fixture.componentInstance.cdr as InternalViewRef<unknown>).checkNoChanges(),
1462+
).toThrow();
14561463
expect(comp.doCheckCount).toEqual(1);
14571464
expect(comp.contentCheckCount).toEqual(1);
14581465
expect(comp.viewCheckCount).toEqual(1);

packages/core/testing/src/component_fixture.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
getDebugNode,
1919
ɵgetDeferBlocks as getDeferBlocks,
2020
inject,
21+
ɵViewRef as InternalViewRef,
2122
NgZone,
2223
ɵNoopNgZone as NoopNgZone,
2324
RendererFactory2,
@@ -145,10 +146,11 @@ export class ComponentFixture<T> {
145146
* Trigger a change detection cycle for the component.
146147
*/
147148
detectChanges(checkNoChanges = true): void {
148-
const originalCheckNoChanges = this.componentRef.changeDetectorRef.checkNoChanges;
149+
const originalCheckNoChanges = (this.componentRef.changeDetectorRef as InternalViewRef<unknown>)
150+
.checkNoChanges;
149151
try {
150152
if (!checkNoChanges) {
151-
this.componentRef.changeDetectorRef.checkNoChanges = () => {};
153+
(this.componentRef.changeDetectorRef as InternalViewRef<unknown>).checkNoChanges = () => {};
152154
}
153155

154156
if (this.zonelessEnabled) {
@@ -169,15 +171,16 @@ export class ComponentFixture<T> {
169171
});
170172
}
171173
} finally {
172-
this.componentRef.changeDetectorRef.checkNoChanges = originalCheckNoChanges;
174+
(this.componentRef.changeDetectorRef as InternalViewRef<unknown>).checkNoChanges =
175+
originalCheckNoChanges;
173176
}
174177
}
175178

176179
/**
177180
* Do a change detection run to make sure there were no changes.
178181
*/
179182
checkNoChanges(): void {
180-
this.changeDetectorRef.checkNoChanges();
183+
(this.changeDetectorRef as InternalViewRef<unknown>).checkNoChanges();
181184
}
182185

183186
/**

0 commit comments

Comments
 (0)