title: Jasmine - Test method has been called on DOM element from inside Ajax success
body: <p>I am completely new to Jasmine and not sure if I am approaching this correctly.  I want to test that the <code>DataTable()</code> method is called on my table dom element.  This should occur on successful ajax responses.  However, it is initialized inside an ajax call and I'm not sure how to test this.  The javascript function that makes the ajax call is <code>updateResults()</code>.</p>
  
  <p>Here's what I've tried.</p>
  
  <pre><code>describe('#ajax', function () {
      var leaderboards, spyOnAjax;
      var formActionUrl = '/jasmine_test_url';
  
      beforeEach(function () {
          setFixtures('&lt;div class="lb-container"&gt;' +
              '&lt;form class="leaderboard" action="' + formActionUrl + '"&gt;' +
              '&lt;input type="submit"&gt;' +
              '&lt;/form&gt;' +
              '&lt;div id="result-box"&gt;' +
              '&lt;table class="table-leaderboard"&gt;&lt;/table&gt; &lt;/div&gt;' +
              '&lt;/div&gt;');
          leaderboards = new LeaderBoards($('div.lb-container')[0]);
          spyOnAjax = spyOn($, 'ajax').and.callThrough();
          leaderboards.updateResults();
      });
  
      describe('when updateResults method is called on leaderboards object', function () {
  
          it('initializes DataTables', function () {
              var table = $('table.table-leaderboard');
              spyOn(table, 'DataTable');
              expect(table.DataTable).toHaveBeenCalled();
          });
      });
  });
  </code></pre>
  
  <p>Jasmine tells me that it Expected spy DataTable to have been called.
  I don't appear to be getting the table element correctly.  Any advice is appreciated.</p>