Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): improve error msg for invalid KeyValueDiffer.diff arg #15489

Merged
merged 1 commit into from Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
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