本文整理匯總了TypeScript中simulate-event.generate函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript generate函數的具體用法?TypeScript generate怎麽用?TypeScript generate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了generate函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should play back a partial match that was not completed', () => {
let node = createElement();
node.addEventListener('keydown', event => {
keymap.processKeydownEvent(event);
});
let codes: number[] = [];
let keydown = (event: KeyboardEvent) => { codes.push(event.keyCode); };
document.body.addEventListener('keydown', keydown);
let called = false;
let command = commands.addCommand('test', {
execute: () => { called = true; }
});
let binding = keymap.addBinding({
keys: ['D', 'D'],
selector: `#${node.id}`,
command: 'test'
});
let event1 = generate('keydown', { keyCode: 68 });
let event2 = generate('keydown', { keyCode: 69 });
node.dispatchEvent(event1);
expect(codes.length).to.be(0);
node.dispatchEvent(event2);
expect(called).to.be(false);
expect(codes).to.eql([68, 69]);
binding.dispose();
command.dispose();
document.body.removeChild(node);
document.body.removeEventListener('keydown', keydown);
});
示例2: it
it('should register partial and exact matches', () => {
let count1 = 0;
let count2 = 0;
registry.addCommand('test1', {
execute: () => { count1++; }
});
registry.addCommand('test2', {
execute: () => { count2++; }
});
registry.addKeyBinding({
keys: ['Ctrl S'],
selector: `#${elem.id}`,
command: 'test1'
});
registry.addKeyBinding({
keys: ['Ctrl S', 'Ctrl D'],
selector: `#${elem.id}`,
command: 'test2'
});
let event1 = generate('keydown', { keyCode: 83, ctrlKey: true });
let event2 = generate('keydown', { keyCode: 68, ctrlKey: true });
expect(count1).to.equal(0);
expect(count2).to.equal(0);
elem.dispatchEvent(event1);
expect(count1).to.equal(0);
expect(count2).to.equal(0);
elem.dispatchEvent(event2);
expect(count1).to.equal(0);
expect(count2).to.equal(1);
});