title: Testing with jest+enzyme, mock functions is called twice for no reason
body: <p>I'm trying to learn Jest and Enzyme but I'm having a problem I can't find a solution to, this is my test.. it's not very good I know but I'm learning:</p>
  
  <pre><code>import * as apiMock from '../api';
  
  const fakePostId = '1';
  const fakePersona = 'Fake';
  
  jest.mock('../api', () =&gt; {
      return {
          fetchAllComments: jest.fn(() =&gt; {
              return [];
          }),
          filterComments: jest.fn(() =&gt; {
              return [];
          }),
          createCommentObject: jest.fn(() =&gt; {
              return [];
          }),
      };
  });
  
  test('checks if functions are called after didMount', () =&gt; {
      const component = shallow(
          &lt;Comments postId={fakePostId} currentPersona={fakePersona} /&gt;
      );
  
      const spySetComments = jest.spyOn(
          component.instance(),
          'setCommentsFromLocalStorage'
      );
  
      component.instance().componentDidMount();
  
      expect(spySetComments).toHaveBeenCalledTimes(1);
  
      //Don't know why these are called 2! times, I can't see why removing componentDidMount makes it 0.
      expect(apiMock.fetchAllComments).toHaveBeenCalledTimes(1);
      expect(apiMock.filterComments).toHaveBeenCalledTimes(1);
  }
  </code></pre>
  
  <p>The problem is <code>toHaveBeenCalledTimes(1)</code> fails with reason:</p>
  
  <blockquote>
    <p>Expected mock function to have been called one time, but it was called
    two times.</p>
  </blockquote>
  
  <p>But I don't know why.
  <code>setCommentsFromLocalStorage</code> only runs once, and that is the function that sohuld run from componentDidMount and execute these api calls once.</p>
  
  <pre><code>ReactComponent looks like this:
  
  import React, { Component } from 'react';
  import PropTypes from 'prop-types';
  import CreateNewComment from './CreateNewComment';
  import SingleComment from './SingleComment';
  import * as api from '../api';
  
  class Comments extends Component {
    state = {
      comments: []
    };
  
    componentDidMount() {
      this.setCommentsFromLocalStorage();
    }
  
    setCommentsFromLocalStorage = (postId = this.props.postId) =&gt; {
      const fetchedComments = api.fetchAllComments();
      const comments = api.filterComments(fetchedComments, postId);
      this.setState({ comments });
    };
  
    removeComment = commentId =&gt; {
      api.removeComment(commentId);
      this.setCommentsFromLocalStorage();
    };
  
    renderCommentList = (comments, currentPersona) =&gt;
      comments.map(comment =&gt; (
        &lt;SingleComment
          {...comment}
          currentPersona={currentPersona}
          key={comment.id}
          onClick={this.removeComment}
        /&gt;
      ));
  
    render() {
      return (
        &lt;div className="py-2"&gt;
          &lt;h2 className="text-indigo-darker border-b mb-4"&gt;Comments&lt;/h2&gt;
          {this.renderCommentList(this.state.comments, this.props.currentPersona)}
          &lt;CreateNewComment
            postId={this.props.postId}
            author={this.props.currentPersona}
            updateComments={this.setCommentsFromLocalStorage}
          /&gt;
        &lt;/div&gt;
      );
    }
  }
  
  Comments.propTypes = {
    postId: PropTypes.string.isRequired,
    currentPersona: PropTypes.string.isRequired
  };
  
  export default Comments;
  </code></pre>