aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node_modules/undici/docs/api/MockClient.md
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2024-01-28 11:18:12 +0100
committerEgor Tensin <egor@tensin.name>2024-01-28 11:18:12 +0100
commit2d40e8046a08373b1740922690b695a16d5e5fa6 (patch)
treeeb086741d1bb01ef9ed3d0ac8e1301447e835971 /node_modules/undici/docs/api/MockClient.md
parentworkflows/test: upgrade actions (diff)
downloadcleanup-path-2d40e8046a08373b1740922690b695a16d5e5fa6.tar.gz
cleanup-path-2d40e8046a08373b1740922690b695a16d5e5fa6.zip
bump version in package.json, upgrade dependencies
Diffstat (limited to '')
-rw-r--r--node_modules/undici/docs/api/MockClient.md77
1 files changed, 77 insertions, 0 deletions
diff --git a/node_modules/undici/docs/api/MockClient.md b/node_modules/undici/docs/api/MockClient.md
new file mode 100644
index 0000000..ac54691
--- /dev/null
+++ b/node_modules/undici/docs/api/MockClient.md
@@ -0,0 +1,77 @@
+# Class: MockClient
+
+Extends: `undici.Client`
+
+A mock client class that implements the same api as [MockPool](MockPool.md).
+
+## `new MockClient(origin, [options])`
+
+Arguments:
+
+* **origin** `string` - It should only include the **protocol, hostname, and port**.
+* **options** `MockClientOptions` - It extends the `Client` options.
+
+Returns: `MockClient`
+
+### Parameter: `MockClientOptions`
+
+Extends: `ClientOptions`
+
+* **agent** `Agent` - the agent to associate this MockClient with.
+
+### Example - Basic MockClient instantiation
+
+We can use MockAgent to instantiate a MockClient 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.
+
+```js
+import { MockAgent } from 'undici'
+
+// Connections must be set to 1 to return a MockClient instance
+const mockAgent = new MockAgent({ connections: 1 })
+
+const mockClient = mockAgent.get('http://localhost:3000')
+```
+
+## Instance Methods
+
+### `MockClient.intercept(options)`
+
+Implements: [`MockPool.intercept(options)`](MockPool.md#mockpoolinterceptoptions)
+
+### `MockClient.close()`
+
+Implements: [`MockPool.close()`](MockPool.md#mockpoolclose)
+
+### `MockClient.dispatch(options, handlers)`
+
+Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler).
+
+### `MockClient.request(options[, callback])`
+
+See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
+
+#### Example - MockClient request
+
+```js
+import { MockAgent } from 'undici'
+
+const mockAgent = new MockAgent({ connections: 1 })
+
+const mockClient = mockAgent.get('http://localhost:3000')
+mockClient.intercept({ path: '/foo' }).reply(200, 'foo')
+
+const {
+ statusCode,
+ body
+} = await mockClient.request({
+ origin: 'http://localhost:3000',
+ path: '/foo',
+ method: 'GET'
+})
+
+console.log('response received', statusCode) // response received 200
+
+for await (const data of body) {
+ console.log('data', data.toString('utf8')) // data foo
+}
+```