feat(core): add binding name to content changed error (#20352)
Adding the binding name to the error message recieved by the user gives extra context on what exactly changed. The tests are also updated to reflect the new error message. PR Close #20352
This commit is contained in:
parent
7e3f9a482a
commit
d3bf54bdeb
|
@ -98,9 +98,10 @@ export function checkBindingNoChanges(
|
||||||
view: ViewData, def: NodeDef, bindingIdx: number, value: any) {
|
view: ViewData, def: NodeDef, bindingIdx: number, value: any) {
|
||||||
const oldValue = view.oldValues[def.bindingIndex + bindingIdx];
|
const oldValue = view.oldValues[def.bindingIndex + bindingIdx];
|
||||||
if ((view.state & ViewState.BeforeFirstCheck) || !devModeEqual(oldValue, value)) {
|
if ((view.state & ViewState.BeforeFirstCheck) || !devModeEqual(oldValue, value)) {
|
||||||
|
const bindingName = def.bindings[def.bindingIndex].name;
|
||||||
throw expressionChangedAfterItHasBeenCheckedError(
|
throw expressionChangedAfterItHasBeenCheckedError(
|
||||||
Services.createDebugContext(view, def.nodeIndex), oldValue, value,
|
Services.createDebugContext(view, def.nodeIndex), `${bindingName}: ${oldValue}`,
|
||||||
(view.state & ViewState.BeforeFirstCheck) !== 0);
|
`${bindingName}: ${value}`, (view.state & ViewState.BeforeFirstCheck) !== 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ const addEventListener = '__zone_symbol__addEventListener';
|
||||||
value = 'v2';
|
value = 'v2';
|
||||||
expect(() => Services.checkNoChangesView(view))
|
expect(() => Services.checkNoChangesView(view))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'v1'. Current value: 'v2'.`);
|
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'a: v1'. Current value: 'a: v2'.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support detaching and attaching component views for dirty checking', () => {
|
it('should support detaching and attaching component views for dirty checking', () => {
|
||||||
|
|
|
@ -145,7 +145,7 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
|
||||||
childValue = 'v2';
|
childValue = 'v2';
|
||||||
expect(() => Services.checkNoChangesView(parentView))
|
expect(() => Services.checkNoChangesView(parentView))
|
||||||
.toThrowError(
|
.toThrowError(
|
||||||
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'v1'. Current value: 'v2'.`);
|
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'name: v1'. Current value: 'name: v2'.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should destroy embedded views', () => {
|
it('should destroy embedded views', () => {
|
||||||
|
|
Loading…
Reference in New Issue