Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(react-router-dom): streamline jsdom submitter bug workaround (#9824
) Work around the submitter bug in just one place, and link to my jsdom PR which will fix it, so that the workaround can be removed sooner rather than later 🤞 This workaround refactor also establishes a pattern for other jsdom bug polyfills which will be landing in forthcoming RR PRs (the bugs aren't relevant in the current test suite, but will be in the PRs 😅)
- Loading branch information
Showing
5 changed files
with
41 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"react-router-dom": patch | ||
--- | ||
|
||
Streamline jsdom bug workaround in tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ | |
- JakubDrozd | ||
- janpaepke | ||
- jasonpaulos | ||
- jenseng | ||
- JesusTheHun | ||
- jimniels | ||
- jmargeta | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/react-router-dom/__tests__/polyfills/SubmitEvent.submitter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Polyfill jsdom SubmitEvent.submitter, until https://github.com/jsdom/jsdom/pull/3481 is merged | ||
if ( | ||
typeof SubmitEvent === "undefined" || | ||
!SubmitEvent.prototype.hasOwnProperty("submitter") | ||
) { | ||
let maybeSubmitter; | ||
window.addEventListener( | ||
"click", | ||
(event) => { | ||
if ((event.target as any)?.form) maybeSubmitter = event.target; | ||
setImmediate(() => { | ||
// if this click doesn't imminently trigger a submit event, then forget it | ||
maybeSubmitter = undefined; | ||
}); | ||
}, | ||
{ capture: true } | ||
); | ||
window.addEventListener( | ||
"submit", | ||
(event: any) => { | ||
if (maybeSubmitter?.form === event.target) | ||
event.submitter = maybeSubmitter; | ||
}, | ||
{ capture: true } | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters