Skip to content

amqpx v1.0.1


amqpx / extensions/vitest / TestChannel

Class: TestChannel

Defined in: src/extensions/vitest/test-channel.ts:26

Mock implementation of Channel using vitest mocks.

The channel 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, TestChannel } from 'amqpx/vitest';

const connection = new TestConnection();

const channel = connection.createChannel();
// or new TestChannel();

const exchange = channel.createExchange();

expect(exchange).toBeInstanceOf(TestExchange);

Extends

  • EventEmitter

Implements

Constructors

Constructor

new TestChannel(connection?): TestChannel

Defined in: src/extensions/vitest/test-channel.ts:28

Parameters

ParameterType
connectionConnection

Returns

TestChannel

Overrides

EventEmitter.constructor

Properties

PropertyModifierTypeDescriptionDefined in
checkQueuepublicMock<Procedure>Check whether a queue exists on the broker without asserting it. Resolves with queue metadata; rejects if the queue does not exist. Param Queue name to inspect.src/extensions/vitest/test-channel.ts:82
closepublicMock<Procedure>Close the underlying amqplib channel. For confirm channels, waits for all pending confirmations before closing. Param Maximum milliseconds to wait for pending confirmations before closing. Throws 'Channel close timed out' if exceeded. Waits 30s when omitted.src/extensions/vitest/test-channel.ts:34
connectpublicMock<Procedure>Open the underlying amqplib channel. Must be called before any other operation. Subsequent calls are no-ops if the channel is already open.src/extensions/vitest/test-channel.ts:32
connectionreadonlyConnection-src/extensions/vitest/test-channel.ts:28
consumeResponsepublicobject-src/extensions/vitest/test-channel.ts:113
consumeResponse.consumerTagpublic`${string}-${string}-${string}-${string}-${string}`-src/extensions/vitest/test-channel.ts:114
createBatchConsumerForExchangepublicMock<Procedure>Create a batch consumer that reads from an exchange using this channel. Internally asserts an exclusive queue and binds it to the exchange. Each consumer should have its own dedicated channel; this method uses the current channel. Consider using connection.createBatchConsumerForExchange or pass a channel in options param. Param Source exchange. Param Batch consumer options including the binding pattern. Param Options for the auto-created exclusive queue binding.src/extensions/vitest/test-channel.ts:64
createBatchConsumerForQueuepublicMock<Procedure>Create a batch consumer that reads from a queue using this channel. Each consumer should have its own dedicated channel; this method uses the current channel. Consider using connection.createBatchConsumerForQueue or pass a channel in options param. Param Source queue. Param Optional batch consumer options (batch size, failure strategy, prefetch, …).src/extensions/vitest/test-channel.ts:60
createConsumerForExchangepublicMock<Procedure>Create a consumer that reads from an exchange using this channel. Internally asserts an exclusive queue and binds it to the exchange. Each consumer should have its own dedicated channel; this method uses the current channel. Consider using connection.createConsumerForExchange or pass a channel in options param. Param Source exchange. Param Consumer options including the binding pattern. Param Options for the auto-created exclusive queue binding.src/extensions/vitest/test-channel.ts:56
createConsumerForQueuepublicMock<Procedure>Create a consumer that reads from a queue using this channel. Each consumer should have its own dedicated channel; this method uses the current channel. Consider using connection.createConsumerForQueue or pass a channel in options param. Param Source queue. Param Optional consumer options (failure strategy, prefetch, …).src/extensions/vitest/test-channel.ts:52
createExchangepublicMock<Procedure>Assert an exchange on the broker and return an Exchange handle. Param Exchange name. Param Exchange type (direct, fanout, topic, headers, …). Param Optional exchange assertion options.src/extensions/vitest/test-channel.ts:36
createProducerForExchangepublicMock<Procedure>Create a producer that publishes to an exchange using this channel. Each producer should have its own dedicated channel; this method uses the current channel. Consider using connection.createProducerForExchange or pass a channel in options param. Param Target exchange. Param Optional producer options (serialization, routing key, hooks, …).src/extensions/vitest/test-channel.ts:48
createProducerForQueuepublicMock<Procedure>Create a producer that publishes directly to a queue using this channel. Each producer should have its own dedicated channel; this method uses the current channel. Consider using connection.createProducerForQueue or pass a channel in options param. Param Target queue. Param Optional producer options (serialization, routing key, hooks, …).src/extensions/vitest/test-channel.ts:44
createQueuepublicMock<Procedure>Assert a queue on the broker and return a Queue handle. Param Queue name. Param Optional queue assertion options.src/extensions/vitest/test-channel.ts:40
nativepublicMock<Procedure>Returns the underlying amqplib channel, connecting first if not already open. This is intended for internal use.src/extensions/vitest/test-channel.ts:68
nativeChannelpublicobject-src/extensions/vitest/test-channel.ts:117
nativeChannel.ackpublicMock<Procedure>-src/extensions/vitest/test-channel.ts:121
nativeChannel.assertExchangepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:133
nativeChannel.assertQueuepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:123
nativeChannel.bindExchangepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:138
nativeChannel.bindQueuepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:137
nativeChannel.cancelpublicMock<Procedure>-src/extensions/vitest/test-channel.ts:118
nativeChannel.checkExchangepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:136
nativeChannel.checkQueuepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:128
nativeChannel.consumepublicMock<Procedure>-src/extensions/vitest/test-channel.ts:120
nativeChannel.nackpublicMock<Procedure>-src/extensions/vitest/test-channel.ts:122
nativeChannel.prefetchpublicMock<Procedure>-src/extensions/vitest/test-channel.ts:119
publishpublicMock<Procedure>Publish message directly using amqplib publish function. Handles backpressure (drain) and confirm-channel retries automatically. This is intended for internal use. Use createProducer* functions instead. Param Exchange name to publish to. Param Routing key for the message. Param Serialized message body. Param Publish options including drain timeout and retry strategy.src/extensions/vitest/test-channel.ts:73

Methods

releaseDrain()

releaseDrain(): void

Defined in: src/extensions/vitest/test-channel.ts:105

Releases simulated backpressure, resolves all pending publish calls, and emits the drain event.

Returns

void


simulateClose()

simulateClose(): void

Defined in: src/extensions/vitest/test-channel.ts:91

Simulates a channel close by emitting the close event.

Returns

void


simulateDrainBackpressure()

simulateDrainBackpressure(): void

Defined in: src/extensions/vitest/test-channel.ts:98

Simulates write-buffer backpressure. Subsequent publish calls will not resolve until releaseDrain is called.

Returns

void

Released under the MIT License.