0

I want to write unit test but not getting how i can wrte unit test for the following this is my service class

export class TourStoreServiceService {
  private readonly commandMap = new Map<string, BaseCommand>();
  private readonly functionMap = new Map();
  private readonly componentMap = new Map();
  private sessionId: string;
 
  private sessionGenerator: () => string = () => uuidv4();

  constructor(@Inject(LOCAL_STORAGE) private readonly storage: StorageService) {
   
  }
}

I want to test the following functions

 public registerFnRef(key, fn: () => void): void {
    this.functionMap.set(key, fn);
  }

  public registerComponent(key, component: Type<unknown>) {
    this.componentMap.set(key, component);
  }

  public getFnByKey(key): Function {
    return this.functionMap.get(key);
  }

  public getComponentByKey(key): Type<unknown> {
    return this.componentMap.get(key);
  }

  public generateSessionId(): void {
    this.sessionId = this.sessionGenerator();
    this.storage.set('TOUR_SESSION_ID', this.sessionId);
  }
mat.hudak
  • 2,803
  • 2
  • 24
  • 39
Tornado
  • 1,069
  • 12
  • 28
  • any solution? for this code problem???? – Tornado Jul 14 '22 at 12:32
  • You will have to mock `new Map()` using this method: https://stackoverflow.com/a/62935131/7365461. Read the `github` thread linked there as well. I have not found a better way than shown here. – AliF50 Jul 14 '22 at 12:48

0 Answers0