title: Jasmine spyOn on function and returned object
body: <p>I'm using MeteorJS with angular and want to test controller. My controller use $reactive(this).attach($scope). I need to check, if this method was called.</p>
  
  <p>I create something like that for spy:</p>
  
  <pre><code>var $reactive = function(ctrl) {
      return {
          attach:function(scope) {}
      }
  };
  </code></pre>
  
  <p>So I can call it like that:</p>
  
  <pre><code>$reactive('aaa').attach('bbb');
  </code></pre>
  
  <p>How I can do it in tests?</p>
  
  <pre><code>spyOn($reactive, 'attach');
  </code></pre>
  
  <p>Doesn't work. I got <strong>Error: attach() method does not exist</strong></p>
  
  <p>And how to check if it was called?
  This is good call?</p>
  
  <pre><code>expect($reactive).toHaveBeenCalledWith(controller);
  </code></pre>
  
  <p>And how to check that function attach was called with args (scope)?</p>