Complete the code to import the Angular testing module needed for component tests.
import { [1] } from '@angular/core/testing';
The TestBed is the main Angular testing utility to configure and create components for tests.
Complete the code to create a component fixture for testing.
let fixture = TestBed.[1](MyComponent);createComponent creates an instance of the component and its fixture for testing.
Fix the error in the test setup by completing the missing method call to compile components.
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [MyComponent]
}).[1]();
});compileComponents compiles the component's template and CSS asynchronously before tests run.
Fill both blanks to access the component instance and trigger change detection.
const fixture = TestBed.createComponent(MyComponent); const component = fixture.[1]; fixture.[2]();
componentInstance accesses the component object.
detectChanges updates the view with the latest data.
Fill all three blanks to write a test that checks if a component's title renders correctly.
it('should display title', () => { const fixture = TestBed.createComponent(MyComponent); const component = fixture.[1]; component.title = 'Hello'; fixture.[2](); const compiled = fixture.[3]; expect(compiled.querySelector('h1')?.textContent).toContain('Hello'); });
componentInstance accesses the component.
detectChanges updates the view.
nativeElement accesses the DOM element for querying.