Skip to content
Permalink
Browse files

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
  • Loading branch information...
Garbett1 authored and alexeagle committed Nov 11, 2017
1 parent 7e3f9a4 commit d3bf54bdeb0fbd0f5c4eed5c9476d32d4f56aa9e
@@ -98,9 +98,10 @@ export function checkBindingNoChanges(
view: ViewData, def: NodeDef, bindingIdx: number, value: any) {
const oldValue = view.oldValues[def.bindingIndex + bindingIdx];
if ((view.state & ViewState.BeforeFirstCheck) || !devModeEqual(oldValue, value)) {
const bindingName = def.bindings[def.bindingIndex].name;
throw expressionChangedAfterItHasBeenCheckedError(
Services.createDebugContext(view, def.nodeIndex), oldValue, value,
(view.state & ViewState.BeforeFirstCheck) !== 0);
Services.createDebugContext(view, def.nodeIndex), `${bindingName}: ${oldValue}`,
`${bindingName}: ${value}`, (view.state & ViewState.BeforeFirstCheck) !== 0);
}
}

@@ -132,7 +132,7 @@ const addEventListener = '__zone_symbol__addEventListener';
value = 'v2';
expect(() => Services.checkNoChangesView(view))
.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', () => {
@@ -145,7 +145,7 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
childValue = 'v2';
expect(() => Services.checkNoChangesView(parentView))
.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', () => {

0 comments on commit d3bf54b

Please sign in to comment.
You can’t perform that action at this time.