{
  "type": "module",
  "source": "doc/api/api-mockpool.md",
  "modules": [
    {
      "textRaw": "Class: MockPool",
      "name": "class:_mockpool",
      "type": "module",
      "desc": "<p>Extends: <code>undici.Pool</code></p>\n<p>A mock Pool class that implements the Pool API and is used by MockAgent to intercept real requests and return mocked responses.</p>",
      "signatures": [
        {
          "textRaw": "`new MockPool(origin, [options])`",
          "name": "MockPool",
          "type": "ctor",
          "params": [
            {
              "name": "origin"
            },
            {
              "name": "options",
              "optional": true
            }
          ],
          "desc": "<p>Arguments:</p>\n<ul>\n<li><strong>origin</strong> <code>string</code> - It should only include the <strong>protocol, hostname, and port</strong>.</li>\n<li><strong>options</strong> <code>MockPoolOptions</code> - It extends the <code>Pool</code> options.</li>\n</ul>\n<p>Returns: <code>MockPool</code></p>",
          "modules": [
            {
              "textRaw": "Parameter: `MockPoolOptions`",
              "name": "parameter:_`mockpooloptions`",
              "type": "module",
              "desc": "<p>Extends: <code>PoolOptions</code></p>\n<ul>\n<li><strong>agent</strong> <code>Agent</code> - the agent to associate this MockPool with.</li>\n</ul>",
              "displayName": "Parameter: `MockPoolOptions`"
            },
            {
              "textRaw": "Example - Basic MockPool instantiation",
              "name": "example_-_basic_mockpool_instantiation",
              "type": "module",
              "desc": "<p>We can use MockAgent to instantiate a MockPool ready to be used to intercept specified requests. It will not do anything until registered as the agent to use and any mock request are registered.</p>\n<pre><code class=\"language-js\">import { MockAgent } from 'undici'\n\nconst mockAgent = new MockAgent()\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n</code></pre>",
              "displayName": "Example - Basic MockPool instantiation"
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "Instance Methods",
          "name": "instance_methods",
          "type": "module",
          "methods": [
            {
              "textRaw": "`MockPool.intercept(options)`",
              "name": "intercept",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    }
                  ]
                }
              ],
              "desc": "<p>This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance, but each intercept is only used once. For example if you expect to make 2 requests inside a test, you need to call <code>intercept()</code> twice. Assuming you use <code>disableNetConnect()</code> you will get <code>MockNotMatchedError</code> on the second request when you only call <code>intercept()</code> once.</p>\n<p>When defining interception rules, all the rules must pass for a request to be intercepted. If a request is not intercepted, a real request will be attempted.</p>\n<table>\n<thead>\n<tr>\n<th align=\"center\">Matcher type</th>\n<th>Condition to pass</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\"><code>string</code></td>\n<td>Exact match against string</td>\n</tr>\n<tr>\n<td align=\"center\"><code>RegExp</code></td>\n<td>Regex must pass</td>\n</tr>\n<tr>\n<td align=\"center\"><code>Function</code></td>\n<td>Function must return true</td>\n</tr>\n</tbody>\n</table>\n<p>Arguments:</p>\n<ul>\n<li><strong>options</strong> <code>MockPoolInterceptOptions</code> - Interception options.</li>\n</ul>\n<p>Returns: <code>MockInterceptor</code> corresponding to the input options.</p>"
            },
            {
              "textRaw": "`MockPool.close()`",
              "name": "close",
              "type": "method",
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>Closes the mock pool and de-registers from associated MockAgent.</p>\n<p>Returns: <code>Promise&#x3C;void></code></p>",
              "modules": [
                {
                  "textRaw": "Example - clean up after tests are complete",
                  "name": "example_-_clean_up_after_tests_are_complete",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent } from 'undici'\n\nconst mockAgent = new MockAgent()\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nawait mockPool.close()\n</code></pre>",
                  "displayName": "Example - clean up after tests are complete"
                }
              ]
            },
            {
              "textRaw": "`MockPool.dispatch(options, handlers)`",
              "name": "dispatch",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "handlers"
                    }
                  ]
                }
              ],
              "desc": "<p>Implements <a href=\"/docs/docs/api/Dispatcher.html#dispatcherdispatchoptions-handler\"><code>Dispatcher.dispatch(options, handlers)</code></a>.</p>"
            },
            {
              "textRaw": "`MockPool.request(options[, callback])`",
              "name": "request",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherrequestoptions-callback\"><code>Dispatcher.request(options [, callback])</code></a>.</p>",
              "modules": [
                {
                  "textRaw": "Example - MockPool request",
                  "name": "example_-_mockpool_request",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent } from 'undici'\n\nconst mockAgent = new MockAgent()\n\nconst mockPool = mockAgent.get('http://localhost:3000')\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET',\n}).reply(200, 'foo')\n\nconst {\n  statusCode,\n  body\n} = await mockPool.request({\n  origin: 'http://localhost:3000',\n  path: '/foo',\n  method: 'GET'\n})\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - MockPool request"
                }
              ]
            },
            {
              "textRaw": "`MockPool.cleanMocks()`",
              "name": "cleanMocks",
              "type": "method",
              "signatures": [
                {
                  "params": []
                }
              ],
              "desc": "<p>This method cleans up all the prepared mocks.</p>\n<p>Returns: <code>void</code></p>"
            }
          ],
          "modules": [
            {
              "textRaw": "Parameter: `MockPoolInterceptOptions`",
              "name": "parameter:_`mockpoolinterceptoptions`",
              "type": "module",
              "desc": "<ul>\n<li><strong>path</strong> <code>string | RegExp | (path: string) => boolean</code> - a matcher for the HTTP request path. When a <code>RegExp</code> or callback is used, it will match against the request path including all query parameters in alphabetical order. When a <code>string</code> is provided, the query parameters can be conveniently specified through the <code>MockPoolInterceptOptions.query</code> setting.</li>\n<li><strong>method</strong> <code>string | RegExp | (method: string) => boolean</code> - (optional) - a matcher for the HTTP request method. Defaults to <code>GET</code>.</li>\n<li><strong>body</strong> <code>string | RegExp | (body: string) => boolean</code> - (optional) - a matcher for the HTTP request body.</li>\n<li><strong>headers</strong> <code>Record&#x3C;string, string | RegExp | (body: string) => boolean</code>> - (optional) - a matcher for the HTTP request headers. To be intercepted, a request must match all defined headers. Extra headers not defined here may (or may not) be included in the request and do not affect the interception in any way.</li>\n<li><strong>query</strong> <code>Record&#x3C;string, any> | null</code> - (optional) - a matcher for the HTTP request query string params. Only applies when a <code>string</code> was provided for <code>MockPoolInterceptOptions.path</code>.</li>\n<li><strong>ignoreTrailingSlash</strong> <code>boolean</code> - (optional) - set to <code>true</code> if the matcher should also match by ignoring potential trailing slashes in <code>MockPoolInterceptOptions.path</code>.</li>\n</ul>",
              "displayName": "Parameter: `MockPoolInterceptOptions`"
            },
            {
              "textRaw": "Return: `MockInterceptor`",
              "name": "return:_`mockinterceptor`",
              "type": "module",
              "desc": "<p>We can define the behaviour of an intercepted request with the following options.</p>\n<ul>\n<li><strong>reply</strong> <code>(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope</code> - define a reply for a matching request. You can define the replyData as a callback to read incoming request data. Default for <code>responseOptions</code> is <code>{}</code>.</li>\n<li><strong>reply</strong> <code>(callback: MockInterceptor.MockReplyOptionsCallback) => MockScope</code> - define a reply for a matching request, allowing dynamic mocking of all reply options rather than just the data.</li>\n<li><strong>replyWithError</strong> <code>(error: Error) => MockScope</code> - define an error for a matching request to throw.</li>\n<li><strong>defaultReplyHeaders</strong> <code>(headers: Record&#x3C;string, string>) => MockInterceptor</code> - define default headers to be included in subsequent replies. These are in addition to headers on a specific reply.</li>\n<li><strong>defaultReplyTrailers</strong> <code>(trailers: Record&#x3C;string, string>) => MockInterceptor</code> - define default trailers to be included in subsequent replies. These are in addition to trailers on a specific reply.</li>\n<li><strong>replyContentLength</strong> <code>() => MockInterceptor</code> - define automatically calculated <code>content-length</code> headers to be included in subsequent replies.</li>\n</ul>\n<p>The reply data of an intercepted request may either be a string, buffer, or JavaScript object. Objects are converted to JSON while strings and buffers are sent as-is.</p>\n<p>By default, <code>reply</code> and <code>replyWithError</code> define the behaviour for the first matching request only. Subsequent requests will not be affected (this can be changed using the returned <code>MockScope</code>).</p>",
              "displayName": "Return: `MockInterceptor`"
            },
            {
              "textRaw": "Parameter: `MockResponseOptions`",
              "name": "parameter:_`mockresponseoptions`",
              "type": "module",
              "desc": "<ul>\n<li><strong>headers</strong> <code>Record&#x3C;string, string></code> - headers to be included on the mocked reply.</li>\n<li><strong>trailers</strong> <code>Record&#x3C;string, string></code> - trailers to be included on the mocked reply.</li>\n</ul>",
              "displayName": "Parameter: `MockResponseOptions`"
            },
            {
              "textRaw": "Return: `MockScope`",
              "name": "return:_`mockscope`",
              "type": "module",
              "desc": "<p>A <code>MockScope</code> is associated with a single <code>MockInterceptor</code>. With this, we can configure the default behaviour of an intercepted reply.</p>\n<ul>\n<li><strong>delay</strong> <code>(waitInMs: number) => MockScope</code> - delay the associated reply by a set amount in ms.</li>\n<li><strong>persist</strong> <code>() => MockScope</code> - any matching request will always reply with the defined response indefinitely.</li>\n<li><strong>times</strong> <code>(repeatTimes: number) => MockScope</code> - any matching request will reply with the defined response a fixed amount of times. This is overridden by <strong>persist</strong>.</li>\n</ul>",
              "modules": [
                {
                  "textRaw": "Example - Basic Mocked Request",
                  "name": "example_-_basic_mocked_request",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\n// MockPool\nconst mockPool = mockAgent.get('http://localhost:3000')\nmockPool.intercept({ path: '/foo' }).reply(200, 'foo')\n\nconst {\n  statusCode,\n  body\n} = await request('http://localhost:3000/foo')\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - Basic Mocked Request"
                },
                {
                  "textRaw": "Example - Mocked request using reply data callbacks",
                  "name": "example_-_mocked_request_using_reply_data_callbacks",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/echo',\n  method: 'GET',\n  headers: {\n    'User-Agent': 'undici',\n    Host: 'example.com'\n  }\n}).reply(200, ({ headers }) => ({ message: headers.get('message') }))\n\nconst { statusCode, body, headers } = await request('http://localhost:3000', {\n  headers: {\n    message: 'hello world!'\n  }\n})\n\nconsole.log('response received', statusCode) // response received 200\nconsole.log('headers', headers) // { 'content-type': 'application/json' }\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // { \"message\":\"hello world!\" }\n}\n</code></pre>",
                  "displayName": "Example - Mocked request using reply data callbacks"
                },
                {
                  "textRaw": "Example - Mocked request using reply options callback",
                  "name": "example_-_mocked_request_using_reply_options_callback",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/echo',\n  method: 'GET',\n  headers: {\n    'User-Agent': 'undici',\n    Host: 'example.com'\n  }\n}).reply(({ headers }) => ({ statusCode: 200, data: { message: headers.get('message') }})))\n\nconst { statusCode, body, headers } = await request('http://localhost:3000', {\n  headers: {\n    message: 'hello world!'\n  }\n})\n\nconsole.log('response received', statusCode) // response received 200\nconsole.log('headers', headers) // { 'content-type': 'application/json' }\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // { \"message\":\"hello world!\" }\n}\n</code></pre>",
                  "displayName": "Example - Mocked request using reply options callback"
                },
                {
                  "textRaw": "Example - Basic Mocked requests with multiple intercepts",
                  "name": "example_-_basic_mocked_requests_with_multiple_intercepts",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).reply(200, 'foo')\n\nmockPool.intercept({\n  path: '/hello',\n  method: 'GET',\n}).reply(200, 'hello')\n\nconst result1 = await request('http://localhost:3000/foo')\n\nconsole.log('response received', result1.statusCode) // response received 200\n\nfor await (const data of result1.body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n\nconst result2 = await request('http://localhost:3000/hello')\n\nconsole.log('response received', result2.statusCode) // response received 200\n\nfor await (const data of result2.body) {\n  console.log('data', data.toString('utf8')) // data hello\n}\n</code></pre>",
                  "displayName": "Example - Basic Mocked requests with multiple intercepts"
                },
                {
                  "textRaw": "Example - Mocked request with query body, request headers and response headers and trailers",
                  "name": "example_-_mocked_request_with_query_body,_request_headers_and_response_headers_and_trailers",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo?hello=there&#x26;see=ya',\n  method: 'POST',\n  body: 'form1=data1&#x26;form2=data2',\n  headers: {\n    'User-Agent': 'undici',\n    Host: 'example.com'\n  }\n}).reply(200, { foo: 'bar' }, {\n  headers: { 'content-type': 'application/json' },\n  trailers: { 'Content-MD5': 'test' }\n})\n\nconst {\n  statusCode,\n  headers,\n  trailers,\n  body\n} = await request('http://localhost:3000/foo?hello=there&#x26;see=ya', {\n    method: 'POST',\n    body: 'form1=data1&#x26;form2=data2',\n    headers: {\n      foo: 'bar',\n      'User-Agent': 'undici',\n      Host: 'example.com'\n    }\n  })\n\nconsole.log('response received', statusCode) // response received 200\nconsole.log('headers', headers) // { 'content-type': 'application/json' }\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // '{\"foo\":\"bar\"}'\n}\n\nconsole.log('trailers', trailers) // { 'content-md5': 'test' }\n</code></pre>",
                  "displayName": "Example - Mocked request with query body, request headers and response headers and trailers"
                },
                {
                  "textRaw": "Example - Mocked request using different matchers",
                  "name": "example_-_mocked_request_using_different_matchers",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: /^GET$/,\n  body: (value) => value === 'form=data',\n  headers: {\n    'User-Agent': 'undici',\n    Host: /^example.com$/\n  }\n}).reply(200, 'foo')\n\nconst {\n  statusCode,\n  body\n} = await request('http://localhost:3000/foo', {\n  method: 'GET',\n  body: 'form=data',\n  headers: {\n    foo: 'bar',\n    'User-Agent': 'undici',\n    Host: 'example.com'\n  }\n})\n\nconsole.log('response received', statusCode) // response received 200\n\nfor await (const data of body) {\n  console.log('data', data.toString('utf8')) // data foo\n}\n</code></pre>",
                  "displayName": "Example - Mocked request using different matchers"
                },
                {
                  "textRaw": "Example - Mocked request with reply with a defined error",
                  "name": "example_-_mocked_request_with_reply_with_a_defined_error",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).replyWithError(new Error('kaboom'))\n\ntry {\n  await request('http://localhost:3000/foo', {\n    method: 'GET'\n  })\n} catch (error) {\n  console.error(error) // TypeError: fetch failed\n  console.error(error.cause) // Error: kaboom\n}\n</code></pre>",
                  "displayName": "Example - Mocked request with reply with a defined error"
                },
                {
                  "textRaw": "Example - Mocked request with defaultReplyHeaders",
                  "name": "example_-_mocked_request_with_defaultreplyheaders",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).defaultReplyHeaders({ foo: 'bar' })\n  .reply(200, 'foo')\n\nconst { headers } = await request('http://localhost:3000/foo')\n\nconsole.log('headers', headers) // headers { foo: 'bar' }\n</code></pre>",
                  "displayName": "Example - Mocked request with defaultReplyHeaders"
                },
                {
                  "textRaw": "Example - Mocked request with defaultReplyTrailers",
                  "name": "example_-_mocked_request_with_defaultreplytrailers",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).defaultReplyTrailers({ foo: 'bar' })\n  .reply(200, 'foo')\n\nconst { trailers } = await request('http://localhost:3000/foo')\n\nconsole.log('trailers', trailers) // trailers { foo: 'bar' }\n</code></pre>",
                  "displayName": "Example - Mocked request with defaultReplyTrailers"
                },
                {
                  "textRaw": "Example - Mocked request with automatic content-length calculation",
                  "name": "example_-_mocked_request_with_automatic_content-length_calculation",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).replyContentLength().reply(200, 'foo')\n\nconst { headers } = await request('http://localhost:3000/foo')\n\nconsole.log('headers', headers) // headers { 'content-length': '3' }\n</code></pre>",
                  "displayName": "Example - Mocked request with automatic content-length calculation"
                },
                {
                  "textRaw": "Example - Mocked request with automatic content-length calculation on an object",
                  "name": "example_-_mocked_request_with_automatic_content-length_calculation_on_an_object",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).replyContentLength().reply(200, { foo: 'bar' })\n\nconst { headers } = await request('http://localhost:3000/foo')\n\nconsole.log('headers', headers) // headers { 'content-length': '13' }\n</code></pre>",
                  "displayName": "Example - Mocked request with automatic content-length calculation on an object"
                },
                {
                  "textRaw": "Example - Mocked request with persist enabled",
                  "name": "example_-_mocked_request_with_persist_enabled",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).reply(200, 'foo').persist()\n\nconst result1 = await request('http://localhost:3000/foo')\n// Will match and return mocked data\n\nconst result2 = await request('http://localhost:3000/foo')\n// Will match and return mocked data\n\n// Etc\n</code></pre>",
                  "displayName": "Example - Mocked request with persist enabled"
                },
                {
                  "textRaw": "Example - Mocked request with times enabled",
                  "name": "example_-_mocked_request_with_times_enabled",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nmockPool.intercept({\n  path: '/foo',\n  method: 'GET'\n}).reply(200, 'foo').times(2)\n\nconst result1 = await request('http://localhost:3000/foo')\n// Will match and return mocked data\n\nconst result2 = await request('http://localhost:3000/foo')\n// Will match and return mocked data\n\nconst result3 = await request('http://localhost:3000/foo')\n// Will not match and make attempt a real request\n</code></pre>",
                  "displayName": "Example - Mocked request with times enabled"
                },
                {
                  "textRaw": "Example - Mocked request with path callback",
                  "name": "example_-_mocked_request_with_path_callback",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { MockAgent, setGlobalDispatcher, request } from 'undici'\nimport querystring from 'querystring'\n\nconst mockAgent = new MockAgent()\nsetGlobalDispatcher(mockAgent)\n\nconst mockPool = mockAgent.get('http://localhost:3000')\n\nconst matchPath = requestPath => {\n  const [pathname, search] = requestPath.split('?')\n  const requestQuery = querystring.parse(search)\n\n  if (!pathname.startsWith('/foo')) {\n    return false\n  }\n\n  if (!Object.keys(requestQuery).includes('foo') || requestQuery.foo !== 'bar') {\n    return false\n  }\n\n  return true\n}\n\nmockPool.intercept({\n  path: matchPath,\n  method: 'GET'\n}).reply(200, 'foo')\n\nconst result = await request('http://localhost:3000/foo?foo=bar')\n// Will match and return mocked data\n</code></pre>",
                  "displayName": "Example - Mocked request with path callback"
                }
              ],
              "displayName": "Return: `MockScope`"
            }
          ],
          "displayName": "Instance Methods"
        }
      ],
      "displayName": "Class: MockPool"
    }
  ]
}