Commanded v1.0.0 Commanded.Assertions.EventAssertions View Source
Provides test assertion and wait for event functions to help test applications built using Commanded.
The default assert and refute receive timeouts are one second.
You can override the default timeout in config (e.g. config/test.exs
):
config :commanded,
assert_receive_event_timeout: 1_000,
refute_receive_event_timeout: 1_000
Link to this section Summary
Functions
Assert that events matching their respective predicates have a matching correlation id.
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.
Refute that an event of the given type has been received.
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
Assert that an event of the given event type is published. Verify that event using the assertion function.
Example
assert_receive_event(BankApp, BankAccountOpened, fn opened ->
assert opened.account_number == "ACC123"
end)
assert_receive_event(application, event_type, predicate_fn, assertion_fn)
View SourceAssert that an event of the given event type, matching the predicate, is published. Verify that event using the assertion function.
Example
assert_receive_event(BankApp, BankAccountOpened,
fn opened -> opened.account_number == "ACC123" end,
fn opened ->
assert opened.balance == 1_000
end)
do_refute_receive_event(application, subscription, event_type, predicate_fn)
View Sourcerefute_receive_event(application, event_type, opts \\ [], list)
View Source (macro)Refute that an event of the given type has been received.
An optional predicate may be provided to filter events matching the refuted type.
Examples
Refute that ExampleEvent
is created by some_func/0
function:
refute_receive_event(ExampleApp, ExampleEvent) do
some_func()
end
Refute that ExampleEvent
matching given predicate is created by
some_func/0
function:
refute_receive_event(ExampleApp, ExampleEvent,
predicate: fn event -> event.foo == :foo end) do
some_func()
end
Wait for an event of the given event type to be published.
Examples
wait_for_event(BankApp, BankAccountOpened)
Wait for an event of the given event type, matching the predicate, to be published.
Examples
wait_for_event(BankApp, BankAccountOpened, fn opened ->
opened.account_number == "ACC123"
end)