'Jest Mock Signalr

I am building a client that will wrap the SignalR library:

import HubConnection from '@microsoft/signalr';
import { HubConnectionBuilder, LogLevel } from '@microsoft/signalr';
import { ISignalRService } from './ISignalRService';



export default class SignalRService{
private connection
   public async connect(){
      console.log('connect');
     this.connection = await new HubConnectionBuilder()
    .withUrl(URL+"/chatHub")
    .configureLogging(LogLevel.None)
    .build();
   await this.connectionStart()
   }
   public  addSignalRListener(listener:Function){

      //console.log(Function);
      //console.log(listener);
    this.connection.on("ReceiveMessage",listener)
   }
   async connectionStart(): Promise<void> {
      try {
          await this.connection.start({ withCredentials: false });
      } catch (err) {
          
      }
  }
}
//export default SignalRService;

I want to apply Jest Mock in this library. How to implement?

I want to check signalr connected or not and want to test data retrieval



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source