fix(core): improve error msg for invalid KeyValueDiffer.diff arg (#15489)
Closes #15402
This commit is contained in:
parent
a5c972aa8b
commit
b7fa5dec21
|
@ -157,7 +157,8 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
|||
diff(collection: NgIterable<V>): DefaultIterableDiffer<V> {
|
||||
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)) {
|
||||
|
|
|
@ -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<K, V> implements KeyValueDiffer<K, V>, 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;
|
||||
|
|
|
@ -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'/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -220,8 +220,7 @@ export function main() {
|
|||
});
|
||||
|
||||
it('should throw when given an invalid collection', () => {
|
||||
expect(() => differ.diff(<any>'invalid'))
|
||||
.toThrowError('Error trying to diff \'invalid\'');
|
||||
expect(() => differ.diff(<any>'invalid')).toThrowError(/Error trying to diff 'invalid'/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue