Skip to content

Commit

Permalink
fix(core): handle passing undefined to select options pipe (#3326)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Jun 3, 2022
1 parent 3f45390 commit 2299818
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/core/select/src/select-options.pipe.spec.ts
Expand Up @@ -8,6 +8,12 @@ describe('Pipe: FormlySelectOptionsPipe', () => {
pipe = new FormlySelectOptionsPipe();
});

it('passing empty options', () => {
pipe.transform(undefined).subscribe((options) => {
expect(options).toEqual([]);
});
});

it('passing options as an array', () => {
pipe.transform([{ label: '1', value: '1' }]).subscribe((options) => {
expect(options).toEqual([{ label: '1', value: '1', disabled: false }]);
Expand Down Expand Up @@ -54,7 +60,7 @@ describe('Pipe: FormlySelectOptionsPipe', () => {
});

describe('label & value & disabled props', () => {
let options;
let options: any;
beforeEach(() => {
options = [{ name: 'foo', id: '1', locked: true }];
});
Expand All @@ -76,9 +82,9 @@ describe('Pipe: FormlySelectOptionsPipe', () => {
it('as a function', () => {
const field = {
props: {
labelProp: (item) => item.name,
valueProp: (item) => item.id,
disabledProp: (item) => item.locked,
labelProp: (item: any) => item.name,
valueProp: (item: any) => item.id,
disabledProp: (item: any) => item.locked,
},
};

Expand All @@ -96,10 +102,10 @@ describe('Pipe: FormlySelectOptionsPipe', () => {

const field = {
props: {
labelProp: (item) => item.name,
valueProp: (item) => item.id,
disabledProp: (item) => item.locked,
groupProp: (item) => item.parent,
labelProp: (item: any) => item.name,
valueProp: (item: any) => item.id,
disabledProp: (item: any) => item.locked,
groupProp: (item: any) => item.parent,
},
};

Expand All @@ -122,7 +128,7 @@ describe('Pipe: FormlySelectOptionsPipe', () => {
});

describe('group options', () => {
let options;
let options: any;
beforeEach(() => {
options = [
{ label: '1', value: '1', parent: '1' },
Expand Down
2 changes: 1 addition & 1 deletion src/core/select/src/select-options.pipe.ts
Expand Up @@ -40,7 +40,7 @@ export class FormlySelectOptionsPipe implements PipeTransform {
const opts: FormlySelectOption[] = [];
const groups: { [id: string]: number } = {};

options.forEach((option) => {
options?.forEach((option) => {
const o = this.transformOption(option, to);
if (o.group) {
const id = groups[o.label];
Expand Down

0 comments on commit 2299818

Please sign in to comment.