Merge pull request #104 from zhenwenc/fix-field-array-order

Fixed FieldsArray.push to preserve the order of input items
This commit is contained in:
Alexander Cerutti
2022-02-21 22:28:12 +01:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@@ -40,6 +40,15 @@ describe("FieldsArray", () => {
expect(fa[0]).toEqual({ key: "t1", value: "v1" }); expect(fa[0]).toEqual({ key: "t1", value: "v1" });
}); });
it("should preserve order of input items when adding fields", () => {
expect(
fa.push({ key: "t1", value: "v1" }, { key: "t2", value: "v2" })
).toBe(2);
expect(fa.length).toBe(2);
expect(fa[0]).toEqual({ key: "t1", value: "v1" });
expect(fa[1]).toEqual({ key: "t2", value: "v2" });
});
it("should add the key to the pool", () => { it("should add the key to the pool", () => {
fa.push({ key: "t1", value: "v1" }); fa.push({ key: "t1", value: "v1" });

View File

@@ -67,7 +67,7 @@ function registerWithValidation(
let validItems: Schemas.Field[] = []; let validItems: Schemas.Field[] = [];
for (let i = items.length, field: Schemas.Field; (field = items[--i]); ) { for (const field of items) {
try { try {
Schemas.assertValidity( Schemas.assertValidity(
Schemas.Field, Schemas.Field,