In most cases, you just check the external component. If you just want angular to ignore internal components, the easiest way is to add NO_ERRORS_SCHEMA to your specification.
import {NO_ERRORS_SCHEMA} from '@ angular / core'
And then in TestBed.configureTestingModule add the line:
schemas: [NO_ERRORS_SCHEMA]
Then the tests will ignore the fact that you did not import the internal components into your HTML component.
If you want to test the internal component with your external components, if you use angular-cli, you will see that the component.spec file that they automatically generate for you includes an array of declarations , which is part of the TestBed configuration object. So all you have to do is import the file and add the component to your ads.
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 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 installation, just generate a new project in angular-cli and take a look at the specifications it created.
source share