當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。