0

I have created Angular app, and in this app I have created main component that I used two component inline main component with names Article and Header, now inline Article Component I injected service whit name ArticleService now I want to create test for Main Component I'm getting this error : Property 'articleService' is missing in type 'MainComponent' but required in type 'ArticlesComponent'.ts(2741)
How can I fix this problem??
this is my test code for MainComponent:

describe('MainComponent', () => {
  let component: MainComponent;
  let fixture: ComponentFixture<MainComponent>;

  let headcomponent: HeadComponent;
  let ixtureHead: ComponentFixture<HeadComponent>;

  let articlecomponent: ArticlesComponent;
  let ixtureArt: ComponentFixture<ArticlesComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ MainComponent, HeadComponent,ArticlesComponent ]
    })
    .compileComponents();

    fixture = TestBed.createComponent(MainComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();

    ixtureHead = TestBed.createComponent(HeadComponent);
    headcomponent = fixture.componentInstance;
    fixture.detectChanges();

    ixtureArt = TestBed.createComponent(ArticlesComponent);
    articlecomponent = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should create', () => {
    expect(headcomponent).toBeTruthy();
  });

  it('should create', () => {
    expect(articlecomponent).toBeTruthy();
  });
});

and I'm getting this error in this line :

 ixtureArt = TestBed.createComponent(ArticlesComponent);
    articlecomponent = fixture.componentInstance;
    fixture.detectChanges();

and my ArticleComponent test is :

describe('ArticlesComponent', () => {
  let component: ArticlesComponent;
  let fixture: ComponentFixture<ArticlesComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ ArticlesComponent ]
    })
    .compileComponents();

    fixture = TestBed.createComponent(ArticlesComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});
R. Richards
  • 24,603
  • 10
  • 64
  • 64
fardad
  • 1
  • 7

0 Answers0