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(common): KeyValuePipe should return empty array for empty objects #27258

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/common/src/pipes/keyvalue_pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ export interface KeyValue<K, V> {
export class KeyValuePipe implements PipeTransform {
constructor(private readonly differs: KeyValueDiffers) {}

// TODO(issue/24571): remove '!'.
private differ !: KeyValueDiffer<any, any>;
// TODO(issue/24571): remove '!'.
private keyValues !: Array<KeyValue<any, any>>;
private keyValues: Array<KeyValue<any, any>> = [];

transform<K, V>(input: null, compareFn?: (a: KeyValue<K, V>, b: KeyValue<K, V>) => number): null;
transform<V>(
Expand Down
8 changes: 8 additions & 0 deletions packages/common/test/pipes/keyvalue_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ describe('KeyValuePipe', () => {
expect(pipe.transform(fn as any)).toEqual(null);
});
describe('object dictionary', () => {
it('should return empty array of an empty dictionary', () => {
const pipe = new KeyValuePipe(defaultKeyValueDiffers);
expect(pipe.transform({})).toEqual([]);
});
it('should transform a basic dictionary', () => {
const pipe = new KeyValuePipe(defaultKeyValueDiffers);
expect(pipe.transform({1: 2})).toEqual([{key: '1', value: 2}]);
Expand Down Expand Up @@ -62,6 +66,10 @@ describe('KeyValuePipe', () => {
});

describe('Map', () => {
it('should return an empty array for an empty Map', () => {
const pipe = new KeyValuePipe(defaultKeyValueDiffers);
expect(pipe.transform(new Map())).toEqual([]);
});
it('should transform a basic Map', () => {
const pipe = new KeyValuePipe(defaultKeyValueDiffers);
expect(pipe.transform(new Map([[1, 2]]))).toEqual([{key: 1, value: 2}]);
Expand Down