Commanded v0.16.0 Commanded.Assertions.EventAssertions View Source

Provides test assertion and wait for event functions to help test applications built using Commanded.

The default receive timeout is one second.

You can override the default timeout in config (e.g. config/test.exs):

config :commanded,
  assert_receive_event_timeout: 1_000

Link to this section Summary

Functions

Assert that events matching their respective predicates have a matching correlation id. Useful when there is a chain of events that is connected through event handlers

Assert that an event of the given event type is published. Verify that event using the assertion function

Assert that an event of the given event type, matching the predicate, is published. Verify that event using the assertion function

Wait for an event of the given event type to be published

Wait for an event of the given event type, matching the predicate, to be published

Link to this section Functions

Link to this function assert_correlated(event_type_a, predicate_a, event_type_b, predicate_b) View Source

Assert that events matching their respective predicates have a matching correlation id. Useful when there is a chain of events that is connected through event handlers.

Examples

id_one = 1
id_two = 2
assert_correlated(
  BankAccountOpened, fn opened -> opened.id == id_one end,
  InitialAmountDeposited, fn deposited -> deposited.id == id_two end
)
Link to this function assert_receive_event(event_type, assertion_fn) View Source

Assert that an event of the given event type is published. Verify that event using the assertion function.

Examples

assert_receive_event BankAccountOpened, fn opened ->
  assert opened.account_number == "ACC123"
end
Link to this function assert_receive_event(event_type, predicate_fn, assertion_fn) View Source

Assert that an event of the given event type, matching the predicate, is published. Verify that event using the assertion function.

Examples

assert_receive_event BankAccountOpened,
  fn opened -> opened.account_number == "ACC123" end,
  fn opened ->
    assert opened.balance == 1_000
  end
Link to this function wait_for_event(event_type) View Source

Wait for an event of the given event type to be published

Examples

wait_for_event BankAccountOpened
Link to this function wait_for_event(event_type, predicate_fn) View Source

Wait for an event of the given event type, matching the predicate, to be published.

Examples

wait_for_event BankAccountOpened, fn opened -> opened.account_number == "ACC123" end