In most cases you are just testing the outer component. If you just want angular to ignore the inner components, the easiest way is to add the NO_ERRORS_SCHEMA to your spec.
import { NO_ERRORS_SCHEMA } from '@angular/core'
And then in your TestBed.configureTestingModule add the line:
schemas: [NO_ERRORS_SCHEMA]
The tests will then ignore the fact that you have not imported the inner components in your component HTML.
If you want to test the inner component with your outer components, if you're using the angular-cli, you'll see that the component.spec file they automatically generate for you includes a declarations
array that is part of the TestBed configuration object. So all you have to do is import the file and add the component into your declarations.
So your example above:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { MyComponent } from './my-component.component';
import { OtherComponent } from './other-component.component';
Then in your describe
block you will have a beforeEach
beforeEach(async(() =>{
TestBed.configureTestingModule({
declarations: [ MyComponent,
OtherComponent ]
})
.compileComponent();
})
Then your components should now compile correctly without errors. If you want to see the whole setup, just generate a new project in angular-cli and take a look at the spec docs that it generates.