Skip to content

Commit

Permalink
feat(expect-puppeteer): added delay option to element.type for toFill…
Browse files Browse the repository at this point in the history
… matcher (#52)
  • Loading branch information
rkoval authored and gregberge committed May 1, 2018
1 parent 9593fa8 commit ee39ba9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/expect-puppeteer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Expect a control to be in the page or element, then fill it with text.
* `raf` - to constantly execute `pageFunction` in `requestAnimationFrame` callback. This is the tightest polling mode which is suitable to observe styling changes.
* `mutation` - to execute `pageFunction` on every DOM mutation.
* `timeout` <[number]> maximum time to wait for in milliseconds. Defaults to `500`.
* `delay` <[number]> delay to pass to [the puppeteer `element.type` API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#elementhandletypetext-options)

```js
await expect(page).toFill('input[name="firstName"]', 'James')
Expand Down
7 changes: 5 additions & 2 deletions packages/expect-puppeteer/src/matchers/toFill.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import toMatchElement from './toMatchElement'

async function toFill(instance, selector, value, options) {
const element = await toMatchElement(instance, selector, options)
const { delay, ...toMatchElementOptions } = options || {}
const element = await toMatchElement(instance, selector, toMatchElementOptions)
await element.click({ clickCount: 3 })
await element.type(value)
await element.type(value, {
delay,
})
}

export default toFill
10 changes: 10 additions & 0 deletions packages/expect-puppeteer/src/matchers/toFill.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ describe('toFill', () => {
)
expect(value).toBe('James')
})
it('should fill input with custom delay', async () => {
const body = await page.$('body')
await expect(body).toFill('[name="firstName"]', 'James', {
delay: 50
})
const value = await page.evaluate(
() => document.querySelector('[name="firstName"]').value,
)
expect(value).toBe('James')
})

it('should return an error if text is not in the page', async () => {
const body = await page.$('body')
Expand Down

0 comments on commit ee39ba9

Please sign in to comment.