Use Jasmine to stub JS callbacks based on argument values
I've got a JS method in my node.js app that I want to unit test. It makes several calls to a service method, each time passing that service a callback; the callback accumulates the results. How can I use Jasmine to stub out the service method so that each time the stub is called, it calls the callback with a response determined by the arguments? This is (like) the method I'm testing: function methodUnderTest() { var result = []; var f = function(response) {result.push(response)}; service_method(arg1, arg2, f); service_method(other1, other2, f); // Do something with the results... } I want to