View Source LiveEventTest.Assertions (live_event v0.1.1)

Test assertion helpers for LiveEvent.

These assertions are designed to work by passing self() to the event assign under test, and then asserting that the test process received the LiveEvent message.

Link to this section Summary

Functions

Asserts that an event is or was received by the test process.

Asserts that an event was received by the test process.

Asserts that an event isn't or wasn't received by the test process.

Asserts that an event wasn't received by the test process.

Link to this section Functions

Link to this macro

assert_receive_event(event_name, source, payload, timeout \\ nil, failure_message \\ nil)

View Source (macro)
@spec assert_receive_event(
  event_name :: atom(),
  source :: any(),
  payload :: any(),
  timeout :: non_neg_integer() | nil,
  failure_message :: String.t() | nil
) :: any()

Asserts that an event is or was received by the test process.

This is a thin wrapper around ExUnit.Assertions.assert_receive/3, so look there for more docs.

example

Example

# On a LiveComponent with the :on_clicked event assign set to self()
emit(socket, :on_clicked, %{id: 123})

# In the test
assert_receive_event :on_clicked, _source, %{id: 123}
Link to this macro

assert_received_event(event_name, source, payload, failure_message \\ nil)

View Source (macro)
@spec assert_received_event(
  event_name :: atom(),
  source :: any(),
  payload :: any(),
  failure_message :: String.t() | nil
) :: any()

Asserts that an event was received by the test process.

This is a thin wrapper around ExUnit.Assertions.assert_received/2, so look there for more docs.

example

Example

# On a LiveComponent with the :on_clicked event assign set to self()
emit(socket, :on_clicked, %{id: 123})

# In the test
assert_received_event :on_clicked, _source, %{id: 123}
Link to this macro

refute_receive_event(event_name, source, payload, timeout \\ nil, failure_message \\ nil)

View Source (macro)
@spec refute_receive_event(
  event_name :: atom(),
  source :: any(),
  payload :: any(),
  timeout :: non_neg_integer() | nil,
  failure_message :: String.t() | nil
) :: any()

Asserts that an event isn't or wasn't received by the test process.

This is a thin wrapper around ExUnit.Assertions.refute_receive/3, so look there for more docs.

example

Example

# On a LiveComponent with the :on_clicked event assign set to self()
emit(socket, :on_clicked, %{id: 123})

# In the test
refute_receive_event :on_clicked, _source, %{id: 123}
Link to this macro

refute_received_event(event_name, source, payload, failure_message \\ nil)

View Source (macro)
@spec refute_received_event(
  event_name :: atom(),
  source :: any(),
  payload :: any(),
  failure_message :: String.t() | nil
) :: any()

Asserts that an event wasn't received by the test process.

This is a thin wrapper around ExUnit.Assertions.refute_received/2, so look there for more docs.

example

Example

# On a LiveComponent with the :on_clicked event assign set to self()
emit(socket, :on_clicked, %{id: 123})

# In the test
refute_received_event :on_clicked, _source, %{id: 123}