Angular 6 unit testing component with DomSanitizer dependency

后端 未结 2 1519
情话喂你
情话喂你 2021-02-07 19:42

In a unit test to just create (instantiate) a component that has a DomSanitizer dependency, how does one mock / stub this dependency?

Because DomSanit

2条回答
  •  北海茫月
    2021-02-07 20:43

    If you want to preserve the value, use:

    {
      provide: DomSanitizer,
      useValue: {
        sanitize: (ctx: any, val: string) => val,
        bypassSecurityTrustResourceUrl: (val: string) => val,
      },
    }
    

提交回复
热议问题