What makes the stub call the first callback?
Causes the stub to call the first callback it receives with the supplied arguments (if any). If a method accepts more than one callback, you must use yieldsRight to call the last callback or callsArg to have the stub call other callbacks besides the first or last one. stub.yieldsRight ( [arg1, arg2.])
Table of Contents
Why do you need a success callback function in jQuery?
This decouples callback handling from AJAX handling, allows you to add multiple callbacks, failed callbacks, etc., all without needing to modify the original getData() function. Separating the AJAX functionality from the set of actions that will be completed later is a good thing!
When to call the original method wrapped in a stub?
If the argument at the provided index is not available or is not a function, a TypeError will be raised. Causes the original method wrapped in the stub to be called when none of the conditional stubs match. Causes the original method wrapped in the stub to be called using the new operator when none of the conditional stubs match.
Do you need to declare a variable on ajax success?
It is not necessary to declare the variable. The Ajax success function automatically takes up to 3 parameters: Function (object data, String textStatus, jqXHR jqXHR)
How does the exception throw stub test work?
The test verifies that all the callbacks were called, and also that the exception throwing stub was called before one of the other callbacks. Calling methods that define behavior such as returns or throws multiple times overrides the stub behavior.
What makes the stub return a promise?
Causes the stub to return a Promise that is rejected with an exception of the provided type. Causes the stub to return a Promise which is rejected with the provided exception object. Causes the stub to call the argument at the given index as a callback function. stub.callsArg(0); causes the stub to call the first argument as a callback.
How to make a stub respond differently on consecutive calls?
As of Sinon version 1.8, you can use the onCall method to make a stub respond differently on consecutive calls. Note that in Sinon version 1.5 to 1.7, multiple calls to the yields* and callsArg* family of methods define a sequence of behaviors for consecutive calls. As of 1.8, this functionality has been removed in favor of the onCall API.