title: How to test jQuery with Jasmine for $("#element-id") if used as $(this)
body: <p>I don't know how to run this Jasmine test for my JS and surely also other ppl have this problem. Maybe I'm doing st wrong or maybe it's impossible - I didn't find any hint on this. The problem has to do with the fact that - in jQuery - $(this) is not the same as the element chosen by e.g. $("#this-id"):</p>
  
  <p>Javascript:</p>
  
  <pre><code>[..]
  $("#button-id").on("click", function(e) { callSomeFunctionWith( $(this) ); } );
  </code></pre>
  
  <p>Jasmine-Test (CoffeeScript):</p>
  
  <pre><code>[..]
  spyOn some.object, "callSomeFunctionWith"
  spyOnEvent( $("#button-id"), 'click' )
  
  $("#button-id").trigger( "click" )
  expect( some.object.callSomeFunctionWith ).toHaveBeenCalledWith( $("#button-id") )
  </code></pre>
  
  <p>Unfortunately this test fails (with any variation like storing the ref to in a variable first in my Jasmine test), because the function is NOT called with $("#button-id"), but instead is called with $(this), and $(this) != $("#button-id").</p>
  
  <p>Can anybody tell me how to accomplish this test? I'm quite lost. Even <a href="http://remysharp.com/2007/04/12/jquerys-this-demystified/" rel="noreferrer">Remy Sharp's great article on jQuery and $(this)</a> didn't get me any further.</p>