withTestFinisherFunction(mockName, funcName, iteration)

Set a mocked proxy function as the finisher function for the test. When the finisher function is executed, the test will be considered complete, the mocks will begin being tested, and then the provided testable function will be executed. i.e. By setting this function, you are telling Maddox when the test is complete.

A common use case for using this function, is if you want to execute a set of code asynchronously but you don't care about the result. For Example: Let's say you want to call an HTTP endpoint to execute some code, but you want the HTTP endpoint to provide an immediate acknowledgement. In other words, you want to end the HTTP Request without waiting for the code behind the Http endpoint to be finished. Even though you want the HTTP request to finish immediately, you still want to test that the other mocks are called with the expected parameters. Normally when using the HttpReqScenario, your finisher function is automatically assigned within Maddox. Often the finisher function will be res.send, because that is the function that is commonly used to finish Http Requests via Express. This function will now tell Maddox that the execution is complete, and that Maddox can begin testing the mocks. By setting a finisher function, you are now telling Maddox to wait until finisher function has been executed before beginning to test the mocks.

As always, there are detailed examples in the unit tests of Maddox to see how this can be used. But I will also be publishing specific examples of this use case since it isn't that common.

  • mockName {String} - This is the key for the mock. It will be used again in other functions and is used in Maddox to keep track of mocks.
  • funcName {String} - The name of the function to be mocked.
  • [iteration] {Number} - Defaults to 0. The finisher function will be executed the nth time this mocked proxy function is executed. Iterations start at 0. So if you want the finisher function to called on the second time a mocked proxy is called, then you would pass in 1.
  • returns {Scenario}