title: How do I test that forEach is calling savePost three times?
body: <p>I am learning how to write tests in JavaScript and I have this code here:</p>
  <pre><code>function handlePosts() {
      var posts = [
        { id: 23, title: 'Me Gusta JS' },
        { id: 52, title: 'Ciudad Código' },
        { id: 105, title: 'Programar Ya' }
      ];
      
      for (var i = 0; i &lt; posts.length; i++) {
        savePost(posts[i]);
      }
  }
  </code></pre>
  <p>That calls <code>savePost</code> three times, but I am wanting to ensure that when I or someone else utilizes, specifically the <code>forEach</code> helper method, that one of my tests looks for the <code>forEach</code> actually calling <code>savePost</code> three times.</p>
  <p>I already developed a test to check that the <code>forEach</code> exists, in other words it's being used, as opposed to some other array helper method, but not sure how to test that it's doing what it should be doing.</p>
  <pre><code>describe('forEach', function() {
      it('forEach method exists', () =&gt; {
          expect(forEach).toBeDefined();
      });
      
      it('forEach is calling savePost three times', () =&gt; {
          
      });
  });
  </code></pre>
  <p>I am keen to gain an understanding of how to think about this, rather than just an answer.</p>
  <p>I imagine something like <code>expect(savePost.length).toEqual(3);</code>, but I am not sure.</p>