Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've never done any testing with jasmine, but I think I understand your problem. I would restructure the code a little to allow for you to wrap the function being called in a proxy function like this:</p> <p>Modify your code that is being test to extract the setTimeout code into another function:</p> <p>Original Code:</p> <pre><code>// Disables all submit buttons after a submit button is pressed. var block_all_submit_and_ajax = function( el ) { // Clone the clicked button, we need to know what button has been clicked so that we can react accordingly var $clone = $( el ).clone(); // Change the type to hidden $clone.attr( 'type', 'hidden' ); // Put the hidden button in the DOM $( el ).after( $clone ); // Disable all submit button. I use setTimeout otherwise this doesn't work in chrome. setTimeout(function() { $( '#facebook input[type=submit]' ).prop( 'disabled', true ); }, 10); // unbind all click handler from ajax $( '#facebook a.btn' ).unbind( "click" ); // Disable all AJAX buttons. $( '#facebook a.btn' ).click( function( e ) { e.preventDefault(); e.stopImmediatePropagation(); } ); }; </code></pre> <p>Modified Code:</p> <pre><code>// Disables all submit buttons after a submit button is pressed. var block_all_submit_and_ajax = function( el ) { // Clone the clicked button, we need to know what button has been clicked so that we can react accordingly var $clone = $( el ).clone(); // Change the type to hidden $clone.attr( 'type', 'hidden' ); // Put the hidden button in the DOM $( el ).after( $clone ); // Disable all submit button. I use setTimeout otherwise this doesn't work in chrome. setTimeout(disableSubmitButtons, 10); // unbind all click handler from ajax $( '#facebook a.btn' ).unbind( "click" ); // Disable all AJAX buttons. $( '#facebook a.btn' ).click( function( e ) { e.preventDefault(); e.stopImmediatePropagation(); } ); }; var utilityFunctions = { disableSubmitButtons : function() { $( '#facebook input[type=submit]' ).prop( 'disabled', true ); } } </code></pre> <p>Next I would modify the testing code like this:</p> <pre><code>it( "Disable all submit buttons", function() { // Get a button var $button = $( '#ai1ec_subscribe_users' ); var originalFunction = utilityFunctions.disableSubmitButtons; utilityFunctions.disableSubmitButtons = function() { // call the original code, and follow it up with the test originalFunction(); // check that all submit are disabled $( '#facebook input[type=submit]' ).each( function( i, el ) { console.log( 'f' ); expect( el ).toHaveProp( 'disabled', true ); }); // set things back the way they were utilityFunctions.disableSubmitButtons = originalFunction; } // Call the function utility_functions.block_all_submit_and_ajax( $button.get(0) ); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload