Skip to content

Commit fb21998

Browse files
authored
docs: add page for waitForResponse mock method (#14834)
1 parent e55fec2 commit fb21998

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Wait until at least one matching request has received a response.
3+
*
4+
* <example>
5+
:waitForResponse.js
6+
it('should wait for a matching response', async () => {
7+
const mock = await browser.mock('**/api/**')
8+
9+
// trigger action that issues the request
10+
await $('#load').click()
11+
12+
await mock.waitForResponse({ timeout: 5000 })
13+
expect(mock.calls.length).toBeGreaterThan(0)
14+
})
15+
* </example>
16+
*
17+
* @alias mock.waitForResponse
18+
* @param {WaitForOptions=} options wait options
19+
* @param {Number=} options.timeout max wait time in ms (defaults to `browser.options.waitforTimeout`)
20+
* @param {Number=} options.interval poll interval in ms (defaults to `browser.options.waitforInterval`)
21+
* @param {String=} options.timeoutMsg custom timeout error message
22+
*/
23+
// actual implementation is located in packages/webdriverio/src/utils/interception
24+
25+

website/docs/MocksAndSpies.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,5 @@ expect(mock.calls.length).toBe(1)
187187
// assert response
188188
expect(mock.calls[0].body).toEqual({ success: true })
189189
```
190+
191+
If you need to wait until a matching request has responded, use `mock.waitForResponse(options)`. See the API reference: [waitForResponse](/docs/api/mock/waitForResponse).

website/docs/api/Mock.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Mock objects provide various commands, listed in the `mock` section, that allow
3939
- [`respond`](/docs/api/mock/respond)
4040
- [`respondOnce`](/docs/api/mock/respondOnce)
4141
- [`restore`](/docs/api/mock/restore)
42+
- [`waitForResponse`](/docs/api/mock/waitForResponse)
4243

4344
## Events
4445

0 commit comments

Comments
 (0)