2017-02-22 2 views
0

웹 컴포넌트 테스터 테스트 케이스 내부의 MockInteractions.pressEnter를 사용하여 간단한 입력을 종이 입력으로 시뮬레이션 할 수 없었습니다.웹 컴포넌트 테스터 MockInteractions가 키 누르기 이벤트를 보내지 않습니다.

실제 키보드로 Enter 키를 누르면 작업이 수행됩니다.

여기 내 코드는 누구나 아이디어 나 해결 방법이 있습니까?

<!doctype html> 
    <html> 
    <head> 
     <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> 

     <script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script> 
     <script src="../bower_components/web-component-tester/browser.js"></script> 
     <script src="../bower_components/iron-test-helpers/mock-interactions.js"></script> 


     <link rel="import" href="../bower_components/polymer/polymer.html"> 
     <link rel="import" href="../bower_components/iron-test-helpers/iron-test-helpers.html"> 
     <link rel="import" href="../bower_components/paper-input/paper-input.html"> 

    </head> 
    <body> 
    <test-fixture id="basic"> 

     <template> 
     <dom-module id="search-module"> 
      <template> 
      <paper-input id="searchInput" label="Search" value="{{searchValue}}"></paper-input> 
      </template> 

      <script> 
      (function() { 
       'use strict'; 
       Polymer({ 
       is: 'search-module', 
       properties: { 
        searchValue: String 
       }, 
       listeners: { 
        'searchInput.keypress': '_keyType' 
       }, 
       _keyType: function(keypress) { 
        this.fire('search'); 
       } 
       }); 
      })(); 
      </script> 
     </dom-module> 

     <search-module id="moduleUnderTest"></search-module> 
     </template> 
    </test-fixture> 

    <script> 
     describe('search-module', function() { 
     var element; 

     beforeEach(function() { 
      element = fixture('basic') 
      .find(function(elem){ 
       if(elem.id === 'moduleUnderTest') return elem; 
      }); 
     }); 
     it('should fire search on press enter', function (done) { 
      element.set('searchValue', 'tap enter'); 
      flush(function() { 
      var input = element.$.searchInput; 
      element.addEventListener('search',function() { 
       expect(element.searchValue).to.be.equal('tap enter'); 
       done() 
      }); 
      MockInteractions.focus(input); 
      setTimeout(function() { 
       MockInteractions.pressEnter(input); 
       // pressAndReleaseKeyOn Does not work as well. 
       // MockInteractions.pressAndReleaseKeyOn(input, 'a'.charCodeAt(0)) 
      },500) 
      }) 
     }); 
     }); 
    </script> 

    </body> 
    </html> 

답변

0

해결책을 찾았습니다. 키 다운 이벤트에서 수신 대기하면 이벤트가 올바르게 수신됩니다.

MockInteractions에서 누락 된 기능입니다.

listeners: { 
    'searchInput.keydown': '_keyType' 
    }, 
관련 문제