amqpx / extensions/vitest / TestExchange
Class: TestExchange
Defined in: src/extensions/vitest/test-exchange.ts:20
Mock implementation of Exchange using vitest mocks.
All create* methods return test classes from this package. assert, bindQueue, and bindExchange methods are vitest mocks returning current instance.
Example
ts
import { TestExchange } from 'amqpx/vitest';
const exchange = new TestExchange();
// or create from TestChannel or TestConnection
expect(exchange.bindQueue).toBeCalledTimes(0);Implements
Constructors
Constructor
new TestExchange():
TestExchange
Returns
TestExchange
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
assert | Mock<Procedure> | Verify the exchange against the broker, according to the configured assertionMode. - Assert (default) — declare the exchange; creates it if absent, throws on config mismatch. - Check — verify the exchange exists without creating it; throws if absent. - Passive — no-op; no network call is made. Subsequent calls return immediately once the first call completes successfully. Returns this to allow chaining. | src/extensions/vitest/test-exchange.ts:21 |
bindExchange | Mock<Procedure> | Bind another exchange to this exchange. Asserts the exchange first if it has not been asserted yet. Param Exchange to bind to this exchange. Param Routing key pattern under which to bind. Param Optional AMQP headers or x-arguments for the binding. | src/extensions/vitest/test-exchange.ts:27 |
bindQueue | Mock<Procedure> | Bind a queue to this exchange. Asserts the exchange first if it has not been asserted yet. Param Queue to bind to this exchange. Param Routing key pattern under which to bind. Param Optional AMQP headers or x-arguments for the binding. | src/extensions/vitest/test-exchange.ts:25 |
createBatchConsumer | Mock<Procedure> | Creates a batch consumer for the current exchange. Internally asserts an exclusive queue and binds it to the exchange. Unless specified otherwise, uses the same channel as was used to declare the exchange. This is generally not recommended, as each consumer should have its own dedicated channel. Consider using connection.createBatchConsumerForExchange instead. | src/extensions/vitest/test-exchange.ts:33 |
createConsumer | Mock<Procedure> | Creates a consumer for the current exchange. Internally asserts an exclusive queue and binds it to the exchange. Unless specified otherwise, uses the same channel as was used to declare the exchange. This is generally not recommended, as each consumer should have its own dedicated channel. Consider using connection.createConsumerForExchange instead. | src/extensions/vitest/test-exchange.ts:29 |
createProducer | Mock<Procedure> | Creates a producer for the current exchange. Unless specified otherwise, uses the same channel as was used to declare the exchange. This is generally not recommended, as each producer should have its own dedicated channel. Consider using connection.createProducerForExchange instead. Param Optional producer options (serialization, routing key, hooks, …). Set options.isConfirmed to true to open the dedicated channel in confirm mode. Has no effect when options.channel is supplied. | src/extensions/vitest/test-exchange.ts:37 |
name | Mock<Procedure> | Returns the name of the exchange. Asserts the exchange first if it has not been asserted yet. | src/extensions/vitest/test-exchange.ts:23 |