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