22
33### Table of Contents
44
5- - [ MockServer] [ 1 ]
6- - [ init] [ 2 ]
7- - [ Parameters] [ 3 ]
8- - [ Examples] [ 4 ]
9- - [ InitOptions] [ 5 ]
10- - [ Properties] [ 6 ]
11- - [ MockRequest] [ 7 ]
12- - [ on] [ 8 ]
13- - [ Parameters] [ 9 ]
14- - [ Examples] [ 10 ]
15- - [ ResponseOptions] [ 11 ]
16- - [ Properties] [ 12 ]
5+ * [ MockServer] [ 1 ]
6+ * [ init] [ 2 ]
7+ * [ Parameters] [ 3 ]
8+ * [ Examples] [ 4 ]
9+ * [ InitOptions] [ 5 ]
10+ * [ Properties] [ 6 ]
11+ * [ MockRequest] [ 7 ]
12+ * [ on] [ 8 ]
13+ * [ Parameters] [ 9 ]
14+ * [ Examples] [ 10 ]
15+ * [ ResponseOptions] [ 11 ]
16+ * [ Properties] [ 12 ]
1717
1818## MockServer
1919
@@ -23,8 +23,8 @@ Init mock server and set request interception on the page
2323
2424#### Parameters
2525
26- - ` page ` ** [ Object] [ 13 ] ** Puppeteer's page
27- - ` options ` ** [ InitOptions] [ 14 ] ** init options (optional, default ` {} ` )
26+ * ` page ` ** [ Object] [ 13 ] ** Puppeteer's page
27+ * ` options ` ** [ InitOptions] [ 14 ] ** init options (optional, default ` {} ` )
2828
2929#### Examples
3030
@@ -43,27 +43,27 @@ const mockRequest = await mockServer.init(page, {
4343// now you can use `mockRequest` in your tests
4444```
4545
46- Returns ** [ Promise] [ 15 ] & lt ; [ MockRequest] [ 16 ] >**
46+ Returns ** [ Promise] [ 15 ] < [ MockRequest] [ 16 ] >**
4747
4848## InitOptions
4949
5050Type: [ Object] [ 13 ]
5151
5252### Properties
5353
54- - ` baseAppUrl ` ** [ string] [ 17 ] ** Base app url. By default all requests matching
54+ * ` baseAppUrl ` ** [ string] [ 17 ] ** Base app url. By default all requests matching
5555 base app url are continued.
56- - ` baseApiUrl ` ** [ string] [ 17 ] ** Base api url. By default all requests matching
56+ * ` baseApiUrl ` ** [ string] [ 17 ] ** Base api url. By default all requests matching
5757 base api url are responded with 200 status and empty body, but you will see a
5858 warning in output.
59- - ` onRequest ` ** function (PuppeteerRequest)** Optional callback to be
59+ * ` onRequest ` ** function (PuppeteerRequest)** Optional callback to be
6060 executed for any unhandled request. By default requests are aborted if this
6161 callback is not provided or returns falsy.
62- - ` onAppRequest ` ** function (PuppeteerRequest)** Optional callback to be
62+ * ` onAppRequest ` ** function (PuppeteerRequest)** Optional callback to be
6363 executed for any unhandled app request, i.e. request matching ` baseAppUrl `
6464 option. By default requests are continued if this callback is not provided or
6565 returns falsy.
66- - ` onApiRequest ` ** function (PuppeteerRequest)** Optional callback to be
66+ * ` onApiRequest ` ** function (PuppeteerRequest)** Optional callback to be
6767 executed for any unhandled api request, i.e. request matching ` baseApiUrl `
6868 option. By default requests are responded with ` 200 OK {} ` for convenience if
6969 this callback is not provided or returns falsy.
@@ -80,33 +80,30 @@ Set expected mock response for request. There are also shortcuts `.get()`,
8080
8181#### Parameters
8282
83- - ` method ` ** [ string] [ 17 ] ** request HTTP method
84- - ` endpoint ` ** [ string] [ 17 ] ** request endpoint URL. If relative URL is passed,
83+ * ` method ` ** [ string] [ 17 ] ** request HTTP method
84+ * ` endpoint ` ** [ string] [ 17 ] ** request endpoint URL. If relative URL is passed,
8585 it's considered as a request to api ** relative** to baseApiUrl.
86- - ` status ` ** [ number] [ 18 ] ** response status code
87- - ` response ` ** [ ResponseOptions] [ 19 ] ** additional response options
86+ * ` status ` ** [ number] [ 18 ] ** response status code
87+ * ` response ` ** [ ResponseOptions] [ 19 ] ** additional response options
8888
8989#### Examples
9090
9191Handle request to relative endpoint
9292
93-
9493``` javascript
9594const responseConfig = {body: {result: ' ok' }};
9695mockRequest .on (' get' , ' account' , 200 , responseConfig);
9796```
9897
9998Using shortcut method and absolute url
10099
101-
102100``` javascript
103101const responseConfig = {body: {result: ' not found' }};
104102mockRequest .get (' https://example.com/test' , 404 , responseConfig);
105103```
106104
107105Simulate request timeout
108106
109-
110107``` javascript
111108mockRequest .post (' search' , null , {abort: ' timedout' , delay: 10000 });
112109```
@@ -119,10 +116,10 @@ Type: [Object][13]
119116
120117### Properties
121118
122- - ` body ` ** [ Object] [ 13 ] ** response body
123- - ` delay ` ** [ number] [ 18 ] ?** delay response for N milliseconds
124- - ` abort ` ** [ string] [ 17 ] ?** abort request with supplied error code
125- - ` contentType ` ** [ string] [ 17 ] ?** content type. Defaults to
119+ * ` body ` ** [ Object] [ 13 ] ** response body
120+ * ` delay ` ** ( [ Promise ] [ 15 ] | [ number] [ 18 ] ) ?** delay response for N milliseconds or until promise is resolved
121+ * ` abort ` ** [ string] [ 17 ] ?** abort request with supplied error code
122+ * ` contentType ` ** [ string] [ 17 ] ?** content type. Defaults to
126123 ` application/json ` .
127124
128125[ 1 ] : #mockserver
0 commit comments