amqpx / extensions/vitest / TestConnection
Class: TestConnection
Defined in: src/extensions/vitest/test-connection.ts:27
Mock implementation of Connection using vitest mocks.
The connection is instantly connected and all create* methods return test classes from this package. Non-creation methods return default mock implementations returning undefined (or the same instance if the semantic of the method requires so).
Example
ts
import { TestConnection } from 'amqpx/vitest';
const connection = new TestConnection();
const channel = connection.createChannel();
expect(channel).toBeInstanceOf(TestChannel);Extends
EventEmitter
Implements
Constructors
Constructor
new TestConnection(
options?):TestConnection
Defined in: node_modules/@types/node/events.d.ts:90
Parameters
| Parameter | Type |
|---|---|
options? | EventEmitterOptions |
Returns
TestConnection
Inherited from
EventEmitter.constructor
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
close | Mock<Procedure> | Gracefully closes the connection. Emits the close event after the underlying amqplib connection is fully shut down. Has no effect if the connection is in preconnect or closed state. Param Maximum milliseconds to wait for the underlying connection to close. Throws 'Connection close timed out' if exceeded. Waits 30s when omitted. | src/extensions/vitest/test-connection.ts:28 |
connect | Mock<Procedure> | Establishes the connection. Safe to call concurrently — multiple callers will share the same attempt. After retries are exhausted (ConnectionEventMap.connectionRetryExhausted), the connection moves to the closed state, but connect() may be called again to start a fresh connection attempt. | src/extensions/vitest/test-connection.ts:30 |
createBatchConsumerForExchange | Mock<Procedure> | Creates a batch consumer for an exchange and opens a dedicated channel for it. Internally asserts an exclusive queue and binds it to the exchange. Param Source exchange. Param Batch consumer options, including the binding pattern. Param Options for the auto-created exclusive queue. | src/extensions/vitest/test-connection.ts:46 |
createBatchConsumerForQueue | Mock<Procedure> | Creates a batch consumer for a queue and opens a dedicated channel for it. Param Source queue. Param Optional batch consumer options (batch size, failure strategy, prefetch, …). | src/extensions/vitest/test-connection.ts:42 |
createChannel | Mock<Procedure> | Creates a new channel on this connection. Param If true, creates a confirm channel (publisher confirms enabled). | src/extensions/vitest/test-connection.ts:32 |
createConsumerForExchange | Mock<Procedure> | Creates a consumer for an exchange and opens a dedicated channel for it. Internally asserts an exclusive queue and binds it to the exchange. Param Source exchange. Param Consumer options, including the binding pattern. Param Options for the auto-created exclusive queue. | src/extensions/vitest/test-connection.ts:34 |
createConsumerForQueue | Mock<Procedure> | Creates a consumer for a queue and opens a dedicated channel for it. Param Source queue. Param Optional consumer options (failure strategy, prefetch, …). | src/extensions/vitest/test-connection.ts:38 |
createProducerForExchange | Mock<Procedure> | Creates a producer for an exchange and opens a dedicated channel for it. Param Target exchange. Param Optional producer options (serialization, routing key, hooks, …). Param If true, the dedicated channel uses publisher confirms. | src/extensions/vitest/test-connection.ts:50 |
createProducerForQueue | Mock<Procedure> | Creates a producer for a queue and opens a dedicated channel for it. Param Target queue. Param Optional producer options (serialization, routing key, hooks, …). Param If true, the dedicated channel uses publisher confirms. | src/extensions/vitest/test-connection.ts:54 |
native | Mock<Procedure> | Returns the underlying amqplib connection. Resolves once the connection is established. This is intended for internal use. | src/extensions/vitest/test-connection.ts:58 |
state | Mock<Procedure> | Returns the current state of the connection. | src/extensions/vitest/test-connection.ts:60 |
Methods
simulateDisconnect()
simulateDisconnect():
void
Defined in: src/extensions/vitest/test-connection.ts:65
Simulates a server-side disconnect by emitting the reconnecting event.
Returns
void