Testing & Debugging Flashcards
7 cards from real Angular Web Framework practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Testing & Debugging flashcards as text
Which Angular testing utility method is used to trigger change detection manually in a component test?
Answer: fixture.detectChanges()
fixture.detectChanges() triggers Angular's change detection cycle so the view reflects the component's current state.
What is the purpose of the `NO_ERRORS_SCHEMA` in Angular unit tests?
Answer: It suppresses errors from unknown elements and attributes in templates
NO_ERRORS_SCHEMA tells Angular to ignore unknown elements and attributes, simplifying shallow component testing without declaring child components.
In Angular, what does `fakeAsync` combined with `tick()` allow you to test?
Answer: Asynchronous code by simulating the passage of time
fakeAsync wraps the test in a fake asynchronous zone, and tick() advances the virtual clock to resolve timers and Promises.
Which method on a Jasmine spy allows you to define what value it returns when called?
Answer: spy.and.returnValue()
spy.and.returnValue() configures a Jasmine spy to return a specific value every time the spied function is invoked.
When testing an Angular service that uses HttpClient, which module should be imported in TestBed?
Answer: HttpClientTestingModule
HttpClientTestingModule replaces HttpClient with a mock backend (HttpTestingController) that lets you inspect and flush HTTP requests in tests.
What Angular CLI command runs unit tests and watches for file changes?
Answer: ng test
ng test launches Karma, runs all spec files, and re-runs tests automatically when source files change.
Which Karma configuration option specifies which browsers to use when running Angular tests?
Answer: browsers
The browsers array in karma.conf.js (e.g., ['Chrome', 'ChromeHeadless']) controls which browser environments Karma launches for test execution.