diff --git a/src/packages/get-form-control-payload/get-form-control-payload.js b/src/packages/get-form-control-payload/get-form-control-payload.js index a694ca5..a694030 100644 --- a/src/packages/get-form-control-payload/get-form-control-payload.js +++ b/src/packages/get-form-control-payload/get-form-control-payload.js @@ -51,6 +51,14 @@ const getFormControlsPayload = (...controlElements) => { * @throws {FormPayloadError} */ const getFormControlPayload = (controlNode) => { + const hasType = 'type' in controlNode; + + if (!hasType) { + throw new FormPayloadError({ + message: 'Control element has no type attribute.', + }); + } + switch (controlNode.type) { case ControlType.TEXT: case ControlType.PASSWORD: @@ -129,7 +137,7 @@ const getFormControlPayload = (controlNode) => { } throw new FormPayloadError({ - message: `Unsupported control type – ${controlNode.type}.`, + message: `Unsupported control element type – ${controlNode.type}.`, }); }; diff --git a/tests/get-form-control-payload.test.js b/tests/get-form-control-payload.test.js index 3f70e3d..7f33289 100644 --- a/tests/get-form-control-payload.test.js +++ b/tests/get-form-control-payload.test.js @@ -428,6 +428,12 @@ describe('getFormControlPayload should work correctly', () => { }); describe('should work correctly with an unexpected control type', () => { + test('should throw FormPayloadError for elements without type', () => { + const control = /** @type {HTMLInputElement} */ ({}); + + throws(() => getFormControlPayload(control), FormPayloadError); + }); + test('should throw FormPayloadError with unknown input type', () => { const control = /** @type {HTMLInputElement} */ ({ type: 'unknown-type',