title: Jest Mock inside a JSX Unit Test
body: <p>I have one JSX file to write jest Unit Test.</p>
  
  <p><strong>../dist/container/index</strong></p>
  
  <pre><code>constructor(props) {
  super(props);
  this.state = {
      showName: null
  }
  }
  
  componentWillMount() {
          Request
              .get('/api')
              .end((err, res) =&gt; {
                  if (res) {
                      this.setState({
                          showName: res.name
                      });
                  }
              });
      }
  
  render (
      let { showName } = this.state;
      render (
      {showName ? &lt;div&gt; showName&lt;/div&gt; : &lt;div&gt;No Name&lt;/div&gt; }
  )
  )
  </code></pre>
  
  <p><strong>In test File,</strong></p>
  
  <pre><code>import landing from '../dist/container/index’;
  describe(‘landing’, () =&gt; {
  it(‘check’, () =&gt; { 
  jest.mock('../dist/container/index’, () =&gt; {});
         landing.componentWillMount = jest.fn().mockImplementation(() =&gt; { return { 'a': '2'} });
          const lands = shallow(&lt;landing productDetails={productDetail} messages={messages}/&gt;);
  expect(lands.componentWillMount()).toBeCalledWith({‘a’: '2'});
  })
  });
  </code></pre>
  
  <p>I am getting the below error.</p>
  
  <blockquote>
    <p>expect(jest.fn())[.not].toBeCalledWith()</p>
    
    <p>jest.fn() value must be a mock function or spy. Received:
        object: {"a": "2"}</p>
  </blockquote>
  
  <p>I want to mock the whole componentwillmount calls and need to get the showName, but i am always getting No Name. Any support?</p>