Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(expect-puppeteer): added delay option to element.type for toFill matcher #52

Merged
merged 2 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion packages/expect-puppeteer/src/matchers/toFill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import toMatchElement from './toMatchElement'
async function toFill(instance, selector, value, options) {
const element = await toMatchElement(instance, selector, options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, toMatchElement will receive a delay option that is not required. Can you please avoid this?

const { delay, ...toMatchElementOptions } = options || {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 84841d1

await element.click({ clickCount: 3 })
await element.type(value)
await element.type(value, {
delay: options && options.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