小编And*_*rey的帖子

对具有NgZone依赖关系的组件运行茉莉花测试

我将如何对以下组件进行茉莉花测试:

@Component({
  moduleId: module.id,
  selector: "testComp",
  template: "<div>{{value}}</div>",
})
export class TestComp {
  public value: string = "This is me";
  constructor(public zone: NgZone) {
    this.zone.run(() => console.log("zone is here"));
  }
}
Run Code Online (Sandbox Code Playgroud)

由于无法解析NgZone的所有参数,以下操作失败:

describe("test", () => {
    let fixture;
    let component;

beforeEach(async(() => {
    TestBed.configureTestingModule({
        declarations: [TestComp],
        schemas: [NO_ERRORS_SCHEMA],
        providers: [NgZone]
    }).compileComponents;
}));
beforeEach(() => {
    fixture = TestBed.createComponent(TestComp);
    component = fixture.debugElement.componentInstance;
});
it("should check that the component is created", () => {
    expect(component).toBeTruthy();
});
Run Code Online (Sandbox Code Playgroud)

})

使用Angular 4.1.3。我发现了MockNgZone类@ https://no-shadow-angular-io.firebaseapp.com/docs/ts/latest/api/core/testing/MockNgZone-class.html。但是对于此特定版本,在@ angular …

jasmine angular ngzone

5
推荐指数
5
解决办法
5681
查看次数

标签 统计

angular ×1

jasmine ×1

ngzone ×1