fixes empty key value convert (#2370)
* fixes empty key value convert * Update src/util.ts Co-authored-by: Jon Koops <jonkoops@gmail.com> * fix linting issues * use some() Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
parent
b40da16afd
commit
aaa22e3df0
2 changed files with 16 additions and 1 deletions
|
@ -99,4 +99,16 @@ describe("Tests the form convert util functions", () => {
|
|||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("convert empty to empty object", () => {
|
||||
const given = { attributes: [{ key: "", value: "" }] };
|
||||
|
||||
//when
|
||||
const values = convertFormValuesToObject(given);
|
||||
|
||||
//then
|
||||
expect(values).toEqual({
|
||||
attributes: {},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -73,7 +73,10 @@ const isAttributeArray = (value: any) => {
|
|||
if (!Array.isArray(value)) {
|
||||
return false;
|
||||
}
|
||||
return value.filter((e) => e.key && e.value).length !== 0;
|
||||
|
||||
return value.some(
|
||||
(e) => Object.hasOwn(e, "key") && Object.hasOwn(e, "value")
|
||||
);
|
||||
};
|
||||
|
||||
const isEmpty = (obj: any) => Object.keys(obj).length === 0;
|
||||
|
|
Loading…
Reference in a new issue