test(runtime-dom): add test coverage for v-on runtime guards, fix "exact" guard (#298)

This commit is contained in:
宋铄运
2019-10-16 05:08:44 +08:00
committed by Evan You
parent 3385480ba7
commit db5c343c33
4 changed files with 91 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
const systemModifiers = new Set(['ctrl', 'shift', 'alt', 'meta'])
const systemModifiers = ['ctrl', 'shift', 'alt', 'meta']
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent;
@@ -16,8 +16,8 @@ const modifierGuards: Record<
left: e => 'button' in e && (e as MouseEvent).button !== 0,
middle: e => 'button' in e && (e as MouseEvent).button !== 1,
right: e => 'button' in e && (e as MouseEvent).button !== 2,
exact: (e, modifiers) =>
modifiers!.some(m => systemModifiers.has(m) && (e as any)[`${m}Key`])
exact: (e, modifiers: string[]) =>
systemModifiers.some(m => (e as any)[`${m}Key`] && !modifiers.includes(m))
}
export const vOnModifiersGuard = (fn: Function, modifiers: string[]) => {