mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 19:25:23 +00:00
Added falsy fields to be automatically excluded with warn being emitted
This commit is contained in:
@@ -68,6 +68,18 @@ describe("FieldsArray", () => {
|
|||||||
|
|
||||||
expect(fa.length).toBe(1);
|
expect(fa.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should log a warning if input items contain undefined and, then, ignore it", () => {
|
||||||
|
console.warn = jasmine.createSpy("log");
|
||||||
|
|
||||||
|
fa.push(undefined, { key: "t1", value: "v1" });
|
||||||
|
|
||||||
|
expect(console.warn).toHaveBeenCalledWith(
|
||||||
|
Messages.FIELDS.INVALID.replace("%s", "undefined"),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(fa.length).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("pop", () => {
|
describe("pop", () => {
|
||||||
|
|||||||
@@ -68,6 +68,11 @@ function registerWithValidation(
|
|||||||
let validItems: Schemas.Field[] = [];
|
let validItems: Schemas.Field[] = [];
|
||||||
|
|
||||||
for (const field of items) {
|
for (const field of items) {
|
||||||
|
if (!field) {
|
||||||
|
console.warn(Messages.format(Messages.FIELDS.INVALID, field));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Schemas.assertValidity(
|
Schemas.assertValidity(
|
||||||
Schemas.Field,
|
Schemas.Field,
|
||||||
@@ -76,7 +81,9 @@ function registerWithValidation(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (instance[sharedKeysPoolSymbol].has(field.key)) {
|
if (instance[sharedKeysPoolSymbol].has(field.key)) {
|
||||||
throw Messages.format(Messages.FIELDS.REPEATED_KEY, field.key);
|
throw new TypeError(
|
||||||
|
Messages.format(Messages.FIELDS.REPEATED_KEY, field.key),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance[sharedKeysPoolSymbol].add(field.key);
|
instance[sharedKeysPoolSymbol].add(field.key);
|
||||||
|
|||||||
Reference in New Issue
Block a user