当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript simulate-event.generate函数代码示例

本文整理汇总了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);
      });
开发者ID:rlugojr,项目名称:phosphor,代码行数:33,代码来源:keymap.spec.ts

示例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);
 });
开发者ID:afshin,项目名称:phosphor,代码行数:30,代码来源:index.spec.ts


注:本文中的simulate-event.generate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。