May 1, 2015
Function Callbacks, or lambdas, or blocks, can frequently be nasty to test. Or at least they feel nasty to test. Let’s take a simple JavaScript example:
$("button").click(function() { $("p").html("Warning! A button has been clicked!"); }); This can seem impossible to test, or nearly impossible. In fact callbacks can be really difficult for even experienced TDD practitioners to test. Fortunately it’s really not that hard.
Option 1 - Invoke the Callback JQuery actually makes this pretty easy with clicks.