Skip to content

amqpx v1.0.1


amqpx / extensions/vitest / TestProducer

Class: TestProducer<T>

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

Test implementation of Producer using vitest mocks.

publish method instantly returns the message argument wrapped in a Promise. channel property is a new TestChannel instance.

Example

ts
import { TestProducer } from 'amqpx/vitest';

const producer = new TestProducer();

const channel = producer.getChannel();

expect(channel).toBeInstanceOf(TestChannel);

const msg = await producer.publish('test');

expect(msg).toBe('test');

Extends

  • EventEmitter

Type Parameters

Type Parameter
T

Implements

Constructors

Constructor

new TestProducer<T>(): TestProducer<T>

Defined in: src/extensions/vitest/test-producer.ts:27

Returns

TestProducer<T>

Overrides

EventEmitter.constructor

Properties

PropertyTypeDescriptionDefined in
channelTestChannelThe channel used by this producer for publishing.src/extensions/vitest/test-producer.ts:36
closeMock<Procedure>Stops accepting new publishes and waits for all pending publish operations to settle. Param Maximum milliseconds to wait for pending publishes to settle. Throws 'Producer close timed out' if exceeded. Waits 30s when omitted.src/extensions/vitest/test-producer.ts:32
publishMock<Procedure>Publishes a message to RabbitMQ. Param Message to publish. The producer implementation may augment it with additional properties. Param Either a static routing key string, or a generator function that derives the key from the message. Param Per-publish options such as a retry strategy override.src/extensions/vitest/test-producer.ts:34

Methods

getPublishedMessages()

getPublishedMessages(): T[]

Defined in: src/extensions/vitest/test-producer.ts:41

Returns the first argument (the message payload) from every publish call recorded so far.

Returns

T[]

Released under the MIT License.