0
0
Angularframework~5 mins

Component testing basics in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main goal of component testing in Angular?
To check if an Angular component works correctly by testing its template, class logic, and interaction with inputs and outputs.
Click to reveal answer
beginner
Which Angular testing utility is commonly used to create a test environment for a component?
TestBed is used to configure and create a testing module that mimics an Angular module for the component under test.
Click to reveal answer
intermediate
Why do we use fixture.detectChanges() in Angular component tests?
It triggers Angular's change detection to update the component's template with the latest data and state before assertions.
Click to reveal answer
intermediate
How can you test an @Input property in an Angular component test?
Set the input property directly on the component instance in the test, then call fixture.detectChanges() to update the view.
Click to reveal answer
intermediate
What is the purpose of mocking services in Angular component tests?
To isolate the component by replacing real services with fake ones, so tests focus only on the component's behavior without external dependencies.
Click to reveal answer
Which Angular testing tool helps create a test module for a component?
AHttpClient
BRouter
CNgModule
DTestBed
What does fixture.detectChanges() do in a component test?
ACreates a new component instance
BRuns change detection to update the template
CMocks a service
DClears the test environment
How do you test an @Output event in Angular component testing?
ASubscribe to the event emitter and trigger the event
BSet the @Output property directly
CCall <code>fixture.detectChanges()</code> only
DMock the component
Why mock services in component tests?
ATo isolate the component and avoid real dependencies
BTo speed up the Angular compiler
CTo test the service itself
DTo change component styles
Which lifecycle hook is usually called automatically during fixture.detectChanges()?
AngAfterViewChecked
BngOnDestroy
CngOnInit
DngDoCheck
Explain the steps to set up and run a basic Angular component test.
Think about how you prepare the component and check its output.
You got /5 concepts.
    Describe how to test an Angular component's input and output properties.
    Focus on how data flows in and out of the component.
    You got /4 concepts.