Method: Turbo::Broadcastable::TestHelper#assert_no_turbo_stream_broadcasts

Defined in:
lib/turbo/broadcastable/test_helper.rb

#assert_no_turbo_stream_broadcasts(stream_name_or_object, &block) ⇒ Object

Asserts that no ‘<turbo-stream>` elements were broadcast over Action Cable

Arguments

  • stream_name_or_object the objects used to generate the channel Action Cable name, or the name itself

  • &block optional block executed before the assertion

Asserts that no ‘<turbo-stream>` elements were broadcast:

message = Message.find(1)
message.broadcast_replace_to "messages"

assert_no_turbo_stream_broadcasts "messages" # fails with MiniTest::Assertion error

You can pass a block to run before the assertion:

message = Message.find(1)

assert_no_turbo_stream_broadcasts "messages" do
  # do something other than broadcast to "messages"
end

In addition to a String, the helper also accepts an Object or Array to determine the name of the channel the elements are broadcast to:

message = Message.find(1)

assert_no_turbo_stream_broadcasts message do
  # do something other than broadcast to "message_1"
end

104
105
106
107
108
109
110
111
112
# File 'lib/turbo/broadcastable/test_helper.rb', line 104

def assert_no_turbo_stream_broadcasts(stream_name_or_object, &block)
  block&.call

  stream_name = stream_name_from(stream_name_or_object)

  payloads = broadcasts(stream_name)

  assert payloads.empty?, "Expected no broadcasts on #{stream_name.inspect}, but there were #{payloads.count}"
end