Reputation: 193
Is there a method that I can use to send keys to an input field using web component tester? I'd like to test sending the return key to a form.
Upvotes: 3
Views: 298
Reputation: 138266
I'm not aware of such a method in Web Component Tester, but Polymer's iron-test-helpers
has MockInteractions
that can send keys to a target. It even has one specifically for 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>
Upvotes: 1