Jasmine:模拟ViewChild组件,Angular 2

时间:2017-07-21 14:04:26

标签: javascript angular unit-testing karma-jasmine

我有Parent Component,其View child组件与之关联。我正在尝试为parent component设置单元测试,但我无法使用模拟类覆盖View Child组件。我在架构提供程序中尝试了NO_ERRORS_SCHEMACUSTOM_SCHEMA,并使用了ng2-mock-component

describe('Mobile Application Card:', () => {
  let comp: MobileAppCardComponent;
  let fixture: ComponentFixture<MobileAppCardComponent>;

  beforeEach(() => {

    const mock = MockComponent({ selector: 'bt-modal'}); // View Child Component. 
    TestBed.configureTestingModule({
      declarations: [MobileAppCardComponent, mock],
      providers: [{provide: MobileAppService, useValue: serviceStub},
                  {provide: ToastService, useValue: {}},
                  {provide: Router, userValue: null }
                 ]
    });
    fixture = TestBed.createComponent(MobileAppCardComponent);
  });
});

0 个答案:

没有答案