0

我正在尝试使用 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和 import browserModule 而不是 CommonModule 都无济于事。请问我如何注入这种依赖关系?任何帮助,将不胜感激

4

1 回答 1

0

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

import "core-js/es7/reflect";

感谢这里的线程中的 Odolha https://github.com/angular/angular/issues/19417

于 2018-08-29T09:11:06.610 回答