【问题标题】:DomSanitizer DI failed in jasmineDomSanitizer DI 在茉莉花中失败
【发布时间】:2018-08-29 08:43:51
【问题描述】:

我正在尝试使用 jasmine 测试一个具有以下构造函数的简单组件

constructor(public sanitizer: DomSanitizer) { }

在我的测试中,我有一个类似的测试床

describe("Component: myComponent", () => {
    let component: myComponent;
    let fixture: ComponentFixture<myComponent>;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [FormsModule, CommonModule],
            declarations: [myComponent],
        }).compileComponents().then(() => {
            fixture = TestBed.createComponent(myComponent);
            component = fixture.componentInstance;
        });
    }));
});

我收到了错误

失败:无法解析 myComponent 的所有参数

我什么都试过了。我在Test pipe with dependencies on services 处遵循了关于问题的建议并导入了 browserModule 而不是 CommonModule 都无济于事。请问我如何注入这种依赖关系?任何帮助将不胜感激

【问题讨论】:

    标签: angular jasmine karma-jasmine angular-dom-sanitizer


    【解决方案1】:

    只需在我的tests.ts 中导入下面的依赖项即可解决我的问题。

    import "core-js/es7/reflect";
    

    感谢 Odolha 来自 https://github.com/angular/angular/issues/19417https://github.com/angular/angular/issues/19417

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2014-12-12
      • 1970-01-01
      相关资源
      最近更新 更多