我有 Angular5 项目,我们正在使用 iframe 和 Safe Pipe(使用 DomSanitizer.bypassSecurityTrustResourceUrl 转换站点 url 的自定义管道)在我们的组件中加载外部站点。应用程序运行良好(通过加载站点内容)。
在编写测试用例时,我们遇到了错误。
Chrome 66.0.3359 (Windows 10 0.0.0) DummyComponent toggle button check FAILED
TypeError: this.sanitizer.bypassSecurityTrustResourceUrl is not a function
at SafePipe.transform (webpack:///./src/app/safe.pipe.ts?:21:31)
这是整个测试用例引导启动。
describe('DummyComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
BrowserModule,
HttpClientTestingModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
NoopAnimationsModule,
TranslateModule.forRoot()],
declarations: [DummyComponent, SafePipe],
providers: [NotificationService, TranslateService, DomSanitizer],
}).compileComponents();
});
it('load content', () => {
// expecting content is loading
....
}
}