本文整理汇总了TypeScript中@angular/cdk/testing.createKeyboardEvent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createKeyboardEvent函数的具体用法?TypeScript createKeyboardEvent怎么用?TypeScript createKeyboardEvent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createKeyboardEvent函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should check whether the alt key is pressed', () => {
const event = createKeyboardEvent('keydown', 0);
expect(hasModifierKey(event)).toBe(false);
Object.defineProperty(event, 'altKey', {get: () => true});
expect(hasModifierKey(event)).toBe(true);
});
示例2: createKeyboardEvent
[ENTER, SPACE].forEach(key => {
const event = createKeyboardEvent('keydown', key);
Object.defineProperty(event, 'shiftKey', {get: () => true});
dispatchEvent(optionNativeElement, event);
fixture.detectChanges();
expect(event.defaultPrevented).toBe(false);
});
示例3: it
it('should be able to use keyboard select with SPACE', () => {
let testListItem = listOption[1].nativeElement as HTMLElement;
let SPACE_EVENT: KeyboardEvent =
createKeyboardEvent('keydown', SPACE, testListItem);
let selectList = selectionList.injector.get<MdSelectionList>(MdSelectionList).selectedOptions;
let options = selectionList.componentInstance.options;
let array = options.toArray();
let focusItem = array[1];
expect(selectList.selected.length).toBe(0);
focusItem.focus();
selectionList.componentInstance._keydown(SPACE_EVENT);
fixture.detectChanges();
expect(selectList.selected.length).toBe(1);
});