There is a custom pipe in my Angular application that sanitizes HTML, defined as follows:
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'sanitiseHtml'
})
export class SanitiseHtmlPipe implements PipeTransform {
constructor(private _sanitizer: DomSanitizer) {}
transform(value: any): any {
return this._sanitizer.bypassSecurityTrustHtml(value);
}
}
I am trying to write a test for this pipe like so:
describe('Pipe: Sanitizer', () => {
let pipe: SanitiseHtmlPipe;
beforeEach(() => {
pipe = new SanitiseHtmlPipe(new DomSanitizer());
});
it('should create an instance', () => {
expect(pipe).toBeTruthy();
});
});
The issue I am facing is with the abstract class DomSanatizer which is injected into the constructor like this:
constructor(private _sanitizer: DomSanitizer) {}
Currently, I am getting a TypeScript error stating:
Cannot create an instance of the abstract class 'DomSanitizer'.
I am unsure how TypeScript handles dependency injection in Angular constructors. Does anyone have insights on how to properly test a scenario like this?