Skip to content

Commit 0397079

Browse files
authored
Merge pull request #23 from hyperdivision/type-value
add typeValue helper
2 parents fb95187 + 950e4f2 commit 0397079

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ Accepts a query selector string that resolves to an element or an element. Call
185185

186186
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.
187187

188+
### `await t.typeValue(elementOrQuerySelector, string, [msg])`
189+
190+
Sumulate typing to an `elementOrQuerySelector` by repeatedly setting the value and waiting for a delay.
191+
188192
### `await once(emitter, name, [msg])`
189193

190194
Shortcut to use [`'events.once'`](https://github.com/davidmarkclements/events.once#readme), which is useful for catching events as promises.

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ function create (delay, fn) {
111111
}
112112
return t.delay().then(() => t.pass(msg))
113113
},
114+
async typeValue (stringOrElement, str, msg) {
115+
msg = msg || `Typed by value ${str}${typeof stringOrElement === 'string' ? ` to ${stringOrElement}` : ''}`
116+
const el = toElement(stringOrElement)
117+
for (const c of str.split('')) {
118+
await t.delay()
119+
el.value = el.value != null ? el.value + c : c
120+
}
121+
return t.delay().then(() => t.pass(msg))
122+
},
114123
appendChild (el, msg = 'Appended child to test element') {
115124
t.element.appendChild(el)
116125
return t.onload(el, msg).then(t.delay)

0 commit comments

Comments
 (0)