Skip to content

Commit

Permalink
fix(core): improve error msg for invalid KeyValueDiffer.diff arg (#15489
Browse files Browse the repository at this point in the history
)

Closes #15402
  • Loading branch information
Dzmitry Shylovich authored and vicb committed Mar 29, 2017
1 parent a2c2b87 commit d74e4d0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'/);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'/);
});
});
});
Expand Down

0 comments on commit d74e4d0

Please sign in to comment.