assertBroadcast

Test helper that inspects the ws test log. Returns true iff a recorded wsPublish matched the given channel (and the given event when one is provided). When the optional predicate is a closure, it is called with the recorded data payload and the assertion is true only if the closure returns true. This lets the CFML test suite assert on realtime broadcasts with no live WebSocket client attached.

assertBroadcast( channel [, event [, predicate]] ) → returns boolean

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

channel string
Required

The channel to match against the recorded broadcasts.

event string

An optional event name to match as well. When omitted, any event on the channel matches.

predicate function

An optional closure. When given, it is called with the recorded data payload and must return true for the assertion to pass.

Compatibility

RustCFML:

Test helper; inspects the ws test log written by wsPublish.

Links more information about assertBroadcast

Examples
Sample code invoking the assertBroadcast function

After wsPublish records a broadcast, assertBroadcast confirms it.

wsPublish( channel="/chat", event="message", data={ text="hi" } );

assertBroadcast( "/chat", "message" );                                  // true
assertBroadcast( "/chat", "nope" );                                     // false

Expected Result: true / false

Pass a closure to check the recorded data payload.

assertBroadcast( "/chat", "message", function( d ){ return d.text == "hi"; } );   // true
assertBroadcast( "/chat", "message", function( d ){ return d.text == "bye"; } );  // false

Expected Result: true / false

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub