diff --git a/packages/core/src/change_detection/differs/default_iterable_differ.ts b/packages/core/src/change_detection/differs/default_iterable_differ.ts index 4b94b87270..094c866cf6 100644 --- a/packages/core/src/change_detection/differs/default_iterable_differ.ts +++ b/packages/core/src/change_detection/differs/default_iterable_differ.ts @@ -157,7 +157,8 @@ export class DefaultIterableDiffer implements IterableDiffer, IterableChan diff(collection: NgIterable): DefaultIterableDiffer { if (collection == null) collection = []; if (!isListLikeIterable(collection)) { - throw new Error(`Error trying to diff '${collection}'`); + throw new Error( + `Error trying to diff '${stringify(collection)}'. Only arrays and iterables are allowed`); } if (this.check(collection)) { diff --git a/packages/core/src/change_detection/differs/default_keyvalue_differ.ts b/packages/core/src/change_detection/differs/default_keyvalue_differ.ts index 6c798daf7f..3e4842df76 100644 --- a/packages/core/src/change_detection/differs/default_keyvalue_differ.ts +++ b/packages/core/src/change_detection/differs/default_keyvalue_differ.ts @@ -9,7 +9,6 @@ import {looseIdentical, stringify} from '../../util'; import {isJsObject} from '../change_detection_util'; import {ChangeDetectorRef} from '../change_detector_ref'; - import {KeyValueChangeRecord, KeyValueChanges, KeyValueDiffer, KeyValueDifferFactory} from './keyvalue_differs'; @@ -82,7 +81,8 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer, KeyVal if (!map) { map = new Map(); } else if (!(map instanceof Map || isJsObject(map))) { - throw new Error(`Error trying to diff '${map}'`); + throw new Error( + `Error trying to diff '${stringify(map)}'. Only maps and objects are allowed`); } return this.check(map) ? this : null; diff --git a/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts b/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts index 5e25db3b7d..29bcc3a8c6 100644 --- a/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts +++ b/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts @@ -472,7 +472,7 @@ export function main() { }); it('should throw when given an invalid collection', () => { - expect(() => differ.diff('invalid')).toThrowError('Error trying to diff \'invalid\''); + expect(() => differ.diff('invalid')).toThrowError(/Error trying to diff 'invalid'/); }); }); }); diff --git a/packages/core/test/change_detection/differs/default_keyvalue_differ_spec.ts b/packages/core/test/change_detection/differs/default_keyvalue_differ_spec.ts index c47af412e0..7098a8255c 100644 --- a/packages/core/test/change_detection/differs/default_keyvalue_differ_spec.ts +++ b/packages/core/test/change_detection/differs/default_keyvalue_differ_spec.ts @@ -220,8 +220,7 @@ export function main() { }); it('should throw when given an invalid collection', () => { - expect(() => differ.diff('invalid')) - .toThrowError('Error trying to diff \'invalid\''); + expect(() => differ.diff('invalid')).toThrowError(/Error trying to diff 'invalid'/); }); }); });