Skip to content

Commit 3204490

Browse files
committed
getArrayValues should return empty array instead of null to mimic backend behavior
1 parent f87796d commit 3204490

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/LiveComponent/assets/src/get_array_value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function getArrayValue(
99
element: HTMLElement,
1010
value: string|null,
1111
currentValue: any
12-
): Array<string>|null {
12+
): Array<string> {
1313
// Enforce returned value is an array
1414
if (!(currentValue instanceof Array)) {
1515
currentValue = [];
@@ -35,5 +35,5 @@ export function getArrayValue(
3535
}
3636

3737
// When no values are selected for collection no data should be sent over the wire
38-
return currentValue.length ? currentValue : null;
38+
return currentValue;
3939
}

src/LiveComponent/assets/test/controller/model.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ describe('LiveController data-model Tests', () => {
422422

423423
await waitFor(() => expect(element).toHaveTextContent('Select: foo bar Option 2 is selected'));
424424

425-
mockRerender({ form: {select: null}}, checkboxTemplate);
425+
mockRerender({ form: {select: []}}, checkboxTemplate);
426426

427427
await userEvent.deselectOptions(selectElement, 'bar');
428428

429429
await waitFor(() => expect(element).toHaveTextContent('Select: foo bar Option 2 is unselected'));
430430

431-
expect(controller.dataValue).toEqual({form: {select: null}});
431+
expect(controller.dataValue).toEqual({form: {select: []}});
432432

433433
// assert all calls were done the correct number of times
434434
fetchMock.done();

src/LiveComponent/assets/test/get_array_value.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ describe('getArrayValue', () => {
2121
input.checked = false;
2222

2323
expect(getArrayValue(input, 'foo', null))
24-
.toEqual(null);
24+
.toEqual([]);
2525
expect(getArrayValue(input, 'foo', ['foo']))
26-
.toEqual(null);
26+
.toEqual([]);
2727
expect(getArrayValue(input, 'foo', ['bar']))
2828
.toEqual(['bar']);
2929
expect(getArrayValue(input, 'foo', ['foo', 'bar']))
@@ -41,7 +41,7 @@ describe('getArrayValue', () => {
4141
select.add(barOption);
4242

4343
expect(getArrayValue(select, '', null))
44-
.toEqual(null);
44+
.toEqual([]);
4545

4646
fooOption.selected = true;
4747
expect(getArrayValue(select, '', null))

0 commit comments

Comments
 (0)