Skip to content

Commit

Permalink
Add a blur method
Browse files Browse the repository at this point in the history
You need this when testing focus events.
  • Loading branch information
bcomnes committed Aug 15, 2019
1 parent 31ee0c4 commit 1a13e60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ Accepts a query selector string that resolves to an element or an element. Call

Accepts a query selector string that resolves to an element or an element. Calls `element.focus()` followed by a `t.delay()`.

### `await t.blur(elementOrQuerySelector, [msg])`

Accepts a query selector string that resolves to an element or an element. Calls `element.blur()` followed by a `t.delay()`.

### `await t.type(string, [event], [msg])`

Dispatches `new window.KeyboardEvent` defaulting to the `keydown` event, for each character in `string`. Helpful for typing into the currently focused element on screen. This helper is a WIP, and doesn't work everywhere. Includes a `t.delay()` call so updates are rendered every keypress.
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ function create (delay, fn) {
toElement(stringOrElement).focus()
return t.delay().then(() => t.pass(msg))
},
blur (stringOrElement, msg) {
msg = msg || `Blurred from ${typeof stringOrElement === 'string' ? stringOrElement : 'element'}`
toElement(stringOrElement).blur()
return t.delay().then(() => t.pass(msg))
},
async type (str, event, msg) {
if (typeof event === 'string' && !msg) {
msg = event
Expand Down

0 comments on commit 1a13e60

Please sign in to comment.