【问题标题】:Polymer Web Component Tester sendKeysPolymer Web 组件测试器 sendKeys
【发布时间】:2016-08-16 02:45:55
【问题描述】:

有没有一种方法可以让我使用 Web 组件测试器将键发送到输入字段?我想测试将返回键发送到表单。

【问题讨论】:

    标签: polymer web-component-tester


    【解决方案1】:

    我不知道 Web Component Tester 中有这种方法,但 Polymer 的 iron-test-helpersMockInteractions 可以 send keys to a target。它甚至还有一个专门用于 ENTER 的:MockInteractions.pressEnter(target)

    安装

    bower i --save-dev iron-test-helpers
    

    用法

    <link rel="import" href="iron-test-helpers/iron-test-helpers.html">
    
    <script>
      describe('accessibility', function(done) {
        it('should jump to next page on ENTER key', function() {
          var el = fixture('basic');
          var expectedIndex = el.pageIndex + 1;
    
          MockInteractions.pressEnter(el.$.nextBtn);
    
          // pressEnter() simulates key-down and asynchronous key-up,
          // so wait a while before testing the result
          setTimeout(function() {
            expect(el.pageIndex).to.be.eql(expectedIndex);
            done();
          }, 500);
        });
      });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多