title: how to test function inside another function using jest and typescript
body: <p>I have to test processMsg. But, it is not getting called. following is the code I tried:</p>
  <p>userdata.ts</p>
  <pre><code>import { listen } from './rdkafka';
  export class UserData {
      unsubscribe: any;
      config: any;
  
      constructor() {
          this.config = {
             name: 'msgHandler'
          }
      };
      private processMsg = (value): void =&gt; {
          console.log('param value', value.toString());
          this.unsubscribe();
      };
      getData = (): void =&gt; {
          this.unsubscribe = listen({
              name: this.config.name,
              processMessage: this.processMsg
          });
      };
  }
  </code></pre>
  <p>test.ts</p>
  <pre><code>describe('UserData', () =&gt; {
      let userData: UserData;
      beforeEach(() =&gt; {
          userData = new UserData();
      });
      it('userData', () =&gt; {
          expect(userData.getData()).toBeUndefined();
      })
  })
  </code></pre>
  <p>listen.ts</p>
  <pre><code>const listen = ({name, processMessage}) =&gt; {
      const socket = new WebSocket('ws://localhost:8080');
  
      socket.addEventListener('message', async (data) =&gt; {
          await processMessage(data)
      });
  }
  </code></pre>
  <p>getData method is tested successfully, but need to test listen method inside getData. Any help in this will be really helpful</p>