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:
Erik Jan de Wit 2022-04-05 09:39:32 +02:00 committed by GitHub
parent b40da16afd
commit aaa22e3df0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -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: {},
});
});
});

View file

@ -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;