Angular 6 unit testing component with DomSanitizer dependency

后端 未结 2 1522
情话喂你
情话喂你 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:17

    As a workaround, try add sanitize: () => 'safeString',

    ...
    useValue: {
      sanitize: () => 'safeString',
      bypassSecurityTrustHtml: () => 'safeString'
    }
    ...
    
    0 讨论(0)
  • 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,
      },
    }
    
    0 讨论(0)
提交回复
热议问题