Polymer web组件测试仪MockInteractions不发送按键事件

Polymer web组件测试仪MockInteractions不发送按键事件,polymer,tdd,web-component-tester,Polymer,Tdd,Web Component Tester,我无法在web组件测试用例中使用MockInteractions.pressEnter在纸质输入中模拟简单的按enter键 当我用真正的键盘按enter键时,它就完成了任务 这是我的代码,有人有想法或解决方法吗 <!doctype html> <html> <head> <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-s

我无法在web组件测试用例中使用MockInteractions.pressEnter在纸质输入中模拟简单的按enter键

当我用真正的键盘按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>

(功能(){
"严格使用",;
聚合物({
是:‘搜索模块’,
特性:{
searchValue:String
},
听众:{
“searchInput.keypress':”\u keyType'
},
_按键类型:功能(按键){
这是一场火灾(“搜查”);
}
});
})();
描述('search-module',function(){
var元素;
beforeach(函数(){
元素=夹具('基本')
.find(函数(elem){
if(elem.id==='moduleUnderTest')返回elem;
});
});
它('按enter键应启动搜索')功能(完成){
元素。set('searchValue','tap enter');
刷新(函数(){
变量输入=元素。$.searchInput;
元素。addEventListener('search',函数(){
expect(element.searchValue).to.be.equal('tap enter');
完成()
});
重点(输入);
setTimeout(函数(){
模拟交互。按Enter(输入);
//按和释放键也不起作用。
//模拟交互。按andreleasekeyon(输入'a'。字符编码(0))
},500)
})
});
});
我找到了一个解决方案。 当我监听按键按下事件时,事件被正确捕获

这是MockInteractions中缺少的功能

  listeners: {
    'searchInput.keydown': '_keyType'
  },

它适用于“按键”事件,而不是“按键”事件