Skip to content

Commit

Permalink
[test] polyfill event.keyCode for older browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 23, 2020
1 parent 029d2a2 commit b648fd9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/utils/createClientRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createClientRender(globalOptions = {}) {
}

const fireEvent = Object.assign(rtlFireEvent, {
// polyfill event.key for chrome 49 (supported in Material-UI v4)
// polyfill event.key(Code) for chrome 49 and edge 15 (supported in Material-UI v4)
// for user-interactions react does the polyfilling but manually created
// events don't have this luxury
keyDown(element, options = {}) {
Expand All @@ -103,6 +103,13 @@ const fireEvent = Object.assign(rtlFireEvent, {
return options.key || '';
},
});
if (options.keyCode !== undefined && event.keyCode === 0) {
Object.defineProperty(event, 'keyCode', {
get() {
return options.keyCode;
},
});
}

rtlFireEvent(element, event);
},
Expand All @@ -113,6 +120,13 @@ const fireEvent = Object.assign(rtlFireEvent, {
return options.key || '';
},
});
if (options.keyCode !== undefined && event.keyCode === 0) {
Object.defineProperty(event, 'keyCode', {
get() {
return options.keyCode;
},
});
}

rtlFireEvent(element, event);
},
Expand Down

0 comments on commit b648fd9

Please sign in to comment.