Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to display invalid constraints on form validation in console #3583

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ function transformOptions(options, encoding, mimeType) {
pretendToBeVisual: false,
storageQuota: 5000000,

_reportInvalidConstraintsToConsole: false,

// Defaults filled in later
resourceLoader: undefined,
virtualConsole: undefined,
Expand Down Expand Up @@ -283,6 +285,10 @@ function transformOptions(options, encoding, mimeType) {
transformed.windowOptions.storageQuota = Number(options.storageQuota);
}

if (options._reportInvalidConstraintsToConsole !== undefined) {
transformed.windowOptions._reportInvalidConstraintsToConsole = Boolean(options._reportInvalidConstraintsToConsole);
}

return transformed;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/jsdom/browser/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ function Window(options) {

this._runScripts = options.runScripts;

this._reportInvalidConstraintsToConsole = options._reportInvalidConstraintsToConsole;

// Set up the window as if it's a top level window.
// If it's not, then references will be corrected by frame/iframe code.
this._parent = this._top = this._globalProxy;
Expand Down
6 changes: 6 additions & 0 deletions lib/jsdom/living/nodes/HTMLFormElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@
}

const unhandledInvalidControls = [];
for (const invalidControl of invalidControls) {

Check failure on line 227 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Block must not be padded by blank lines

Check failure on line 227 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Block must not be padded by blank lines

// Report form validation errors to the console for developers debugging why their forms are not submited in tests
if(window._reportInvalidConstraintsToConsole){

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Expected space(s) after "if"

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

'window' is not defined

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Missing space before opening brace

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Expected space(s) after "if"

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

'window' is not defined

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Missing space before opening brace

Check failure on line 230 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
console.error("Form validation failed for "+invalidControl.outerHTML+" with the value: "+ JSON.stringify(invalidControl.value));

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 136. Maximum allowed is 120

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Operator '+' must be spaced

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Operator '+' must be spaced

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Operator '+' must be spaced

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 136. Maximum allowed is 120

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Operator '+' must be spaced

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Operator '+' must be spaced

Check failure on line 231 in lib/jsdom/living/nodes/HTMLFormElement-impl.js

View workflow job for this annotation

GitHub Actions / lint

Operator '+' must be spaced
}

const notCancelled = fireAnEvent("invalid", invalidControl, undefined, { cancelable: true });
if (notCancelled) {
unhandledInvalidControls.push(invalidControl);
Expand Down