title: Using Jasmine how to check if a local method has been called?
body: <p>I am trying to test if a local method (<em>method1</em>) is being called from another method(<em>method2</em>). I tried something like this but it does not work as the method1() still has the <em>original definition</em>. The code snippet looks like this:</p>
  
  <pre><code>var ClassA = function () {
      var method1 = function () {
          console.log('method1');
      };
      var method2 = function () {
          method1();
      };
      return {method1: method1, method2: method2}
  }
  </code></pre>
  
  <p>Test case:</p>
  
  <pre><code>it("should call method1 when method2 is called", function () {
      var objectA = new ClassA();
      spyOn(objectA, 'method1').andCallThrough;
      objectA.method2();
      expect(objectA, 'method1').toHaveBeenCalled();
  });
  </code></pre>
  
  <p>Tried overriding method1 to without any success:</p>
  
  <pre><code>objectA.method1 = jasmine.createSpy('aSpy').andCallThrough();
  </code></pre>