amqpx / extensions/vitest / TestConsumer
Class: TestConsumer<T>
Defined in: src/extensions/vitest/test-consumer.ts:34
Test implementation of Consumer using vitest mocks.
listen method instantly returns current instance wrapped in Promise. You can assert the parameters with which was this method called to assert listen method was called.
queue and channel properties are new instances of TestQueue and TestChannel respectively. All other methods are vitest mocks returning void or the current instance, depending on the method semantic.
Example
import { TestConsumer } from 'amqpx/vitest';
const consumer = new TestConsumer();
const channel = consumer.getChannel();
expect(channel).toBeInstanceOf(TestChannel);
const listener = () => { / * empty * / };
await consumer.listen(listener);
expect(consumer.listen).toBeCalledWith(listener);Extends
EventEmitter
Type Parameters
| Type Parameter |
|---|
T |
Implements
Consumer<T>
Constructors
Constructor
new TestConsumer<
T>():TestConsumer<T>
Defined in: src/extensions/vitest/test-consumer.ts:36
Returns
TestConsumer<T>
Overrides
EventEmitter.constructor
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
channel | TestChannel | The channel used by this consumer. | src/extensions/vitest/test-consumer.ts:49 |
close | Mock<Procedure> | Stops consuming new messages and waits for all in-flight message handlers to finish. Param Maximum time in milliseconds to wait for in-flight messages to complete. Defaults to 30000. | src/extensions/vitest/test-consumer.ts:41 |
listen | Mock<Procedure> | Registers the message handler and starts consuming from the queue. Param Handler invoked for each received message. | src/extensions/vitest/test-consumer.ts:43 |
queue | TestQueue | The queue this consumer reads from. | src/extensions/vitest/test-consumer.ts:47 |
setPrefetch | Mock<Procedure> | - | src/extensions/vitest/test-consumer.ts:45 |
Methods
deliverMessage()
deliverMessage(
message,options?):Promise<void>
Defined in: src/extensions/vitest/test-consumer.ts:57
Simulates a message arriving from RabbitMQ by invoking the most recently registered listener. Throws if listen has not been called yet.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | T | The parsed message payload to deliver. |
options | object & Omit<Partial<ConsumeMessage>, "content"> | Optional serialization override and raw amqplib message field overrides. |
Returns
Promise<void>