本文整理匯總了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);
});