Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 71d63f0

Browse files
committed
Fix tests that mock incomplete key events
1 parent efc5d41 commit 71d63f0

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/KeyBindingsManager.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,35 @@ export function isKeyComboMatch(ev: KeyboardEvent | React.KeyboardEvent, combo:
147147
const comboAlt = combo.altKey ?? false;
148148
const comboShift = combo.shiftKey ?? false;
149149
const comboMeta = combo.metaKey ?? false;
150+
// Tests mock events may keep the modifiers undefined; convert them to booleans
151+
const evCtrl = ev.ctrlKey ?? false;
152+
const evAlt = ev.altKey ?? false;
153+
const evShift = ev.shiftKey ?? false;
154+
const evMeta = ev.metaKey ?? false;
150155
// When ctrlOrCmd is set, the keys need do evaluated differently on PC and Mac
151156
if (combo.ctrlOrCmd) {
152157
if (onMac) {
153-
if (!ev.metaKey
154-
|| ev.ctrlKey !== comboCtrl
155-
|| ev.altKey !== comboAlt
156-
|| ev.shiftKey !== comboShift) {
158+
if (!evMeta
159+
|| evCtrl !== comboCtrl
160+
|| evAlt !== comboAlt
161+
|| evShift !== comboShift) {
157162
return false;
158163
}
159164
} else {
160-
if (!ev.ctrlKey
161-
|| ev.metaKey !== comboMeta
162-
|| ev.altKey !== comboAlt
163-
|| ev.shiftKey !== comboShift) {
165+
if (!evCtrl
166+
|| evMeta !== comboMeta
167+
|| evAlt !== comboAlt
168+
|| evShift !== comboShift) {
164169
return false;
165170
}
166171
}
167172
return true;
168173
}
169174

170-
if (ev.metaKey !== comboMeta
171-
|| ev.ctrlKey !== comboCtrl
172-
|| ev.altKey !== comboAlt
173-
|| ev.shiftKey !== comboShift) {
175+
if (evMeta !== comboMeta
176+
|| evCtrl !== comboCtrl
177+
|| evAlt !== comboAlt
178+
|| evShift !== comboShift) {
174179
return false;
175180
}
176181

0 commit comments

Comments
 (0)