Skip to content

Commit d58d17a

Browse files
committed
feat: also expose waitFor
1 parent 4e077c8 commit d58d17a

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All your favorite user-centric querying functions from @testing-library/react &
1818

1919
```js
2020
const puppeteer = require('puppeteer')
21-
const {getDocument, queries, wait} = require('pptr-testing-library')
21+
const {getDocument, queries, waitFor} = require('pptr-testing-library')
2222

2323
const {getByTestId, getByLabelText} = queries
2424

@@ -34,7 +34,7 @@ const $email = await getByLabelText($form, 'Email')
3434
// interact with puppeteer like usual
3535
await $email.type('[email protected]')
3636
// waiting works too!
37-
await wait(() => getByText($document, 'Loading...'))
37+
await waitFor(() => getByText($document, 'Loading...'))
3838
```
3939

4040
A little too un-puppeteer for you? We've got prototype-mucking covered too :)

lib/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ContextFn = (...args: any[]) => ElementHandle
3535

3636
async function createElementHandleArray(handle: JSHandle): Promise<ElementHandle[]> {
3737
const lengthHandle = await handle.getProperty('length')
38-
const length = await lengthHandle.jsonValue() as number
38+
const length = (await lengthHandle.jsonValue()) as number
3939

4040
const elements: ElementHandle[] = []
4141
for (let i = 0; i < length; i++) {
@@ -132,12 +132,14 @@ export function wait(
132132
return waitForExpect(callback, timeout, interval)
133133
}
134134

135+
export const waitFor = wait
136+
135137
export function configure(options: Partial<IConfigureOptions>): void {
136138
if (!options) {
137139
return
138140
}
139141

140-
const { testIdAttribute } = options
142+
const {testIdAttribute} = options
141143

142144
if (testIdAttribute) {
143145
delegateFnBodyToExecuteInPage = delegateFnBodyToExecuteInPageInitial.replace(

test/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path'
22
import * as puppeteer from 'puppeteer'
3-
import {getDocument, queries, getQueriesForElement, wait, configure} from '../lib'
3+
import {getDocument, queries, getQueriesForElement, waitFor, configure} from '../lib'
44

55
describe('lib/index.ts', () => {
66
let browser: puppeteer.Browser
@@ -61,7 +61,7 @@ describe('lib/index.ts', () => {
6161

6262
it('should use `wait` properly', async () => {
6363
const {getByText} = getQueriesForElement(await getDocument(page))
64-
await wait(() => getByText('Loaded!'), {timeout: 7000})
64+
await waitFor(() => getByText('Loaded!'), {timeout: 7000})
6565
expect(await getByText('Loaded!')).toBeTruthy()
6666
}, 9000)
6767

0 commit comments

Comments
 (0)