title: How to test/mock socket.io client
body: <p>I am trying to mock the emit method from io but I don't know how to mock it. This is my <code>Join.jsx</code> file</p>
  <pre><code>//Join.jsx
  
  import React from 'react';
  import io from 'socket.io-client';
  
  const Join = () =&gt; {
    let socket;
    const ENDPOINT = 'localhost:5000';
  
    const join = () =&gt; {
      socket = io(ENDPOINT);
      socket.emit('join', { name: 'Paola', room: '1' }, () =&gt; { });
    };
  
    return (
      &lt;div className=&quot;join-container&quot;&gt;
          &lt;a className=&quot;join-button&quot; onClick={join}&gt;Sign in&lt;/a&gt;
      &lt;/div&gt;
    );
  };
  
  export default Join;
  </code></pre>
  <p>This is one thing I have tried</p>
  <pre><code>//Join.test.jsx
  import React from 'react';
  import { shallow } from 'enzyme';
  import io from 'socket.io-client';
  import Join from './Join';
  
  describe(('Join') =&gt; {
    it(('joins a chat') =&gt; {
      jest.mock('socket.io-client', () =&gt; {
        return jest.fn(() =&gt; ({
          emit: jest.fn(),
        }));
      });
      const ENDPOINT = 'localhost:5000';
      const mockSocket = io(ENDPOINT);
      const joinWrapper = shallow(&lt;Join /&gt;);
      joinWrapper.find('a').simulate('click');
      expect(mockSocket.emit).toHaveBeenCalledWith('join', { name: 'Paola', room: '1' }, () =&gt; { });
    })
  })
  
  </code></pre>
  <p>This is the error that I get in the terminal</p>
  <pre><code>expect(received).toHaveBeenCalledWith(...expected)
  
      Matcher error: received value must be a mock or spy function
  
      Received has type:  function
      Received has value: [Function anonymous]
  
        52 |     const joinWrapper = shallow(&lt;Join /&gt;);
        53 |     joinWrapper.find('a').simulate('click');
      &gt; 54 |     expect(mockSocket.emit).toHaveBeenCalledWith('join', { name: 'Paola', room: '1' }, () =&gt; { });
           |                             ^
        55 |   });
        56 | });
        57 | 
  
  </code></pre>
  <p>Please don't be rude with your answers, I'm new at testing and I am really lost. Thank you in advance for your responses!!</p>