Jasmine: Mocking ViewChild Component, Angular 2

I have Parent Component

one that has a component associated with it View child

. I am trying to set up a unit test for Parent Component

, but I am unable to override the component View child

with the mock class. I tried NO_ERRORS_SCHEMA

, CUSTOM_SCHEMA

from the scheme provider, as well as used 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);
  });
});
      

Run codeHide result


+3


source to share





All Articles