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
What is the role of `HttpTestingController` in Angular testing?
Answer: It intercepts HTTP requests and allows asserting their parameters and flushing responses
HttpTestingController lets tests verify that specific HTTP requests were made and manually control the responses returned to the service under test.
In Protractor or Cypress E2E tests for Angular, what does waiting for Angular's stability mean?
Answer: Waiting until all pending HTTP requests and asynchronous tasks in Angular's zone have completed
Angular stability means Zone.js has no pending microtasks or macrotasks, ensuring the DOM is in a settled state before assertions run.
Which Jasmine function is used to set up shared initialization code that runs before each test in a describe block?
Answer: beforeEach()
beforeEach() runs its callback before every it() block in its enclosing describe, making it ideal for resetting state between tests.
What does calling `fixture.nativeElement.querySelector('.my-class')` return in a component test?
Answer: The DOM element matching the CSS selector within the component's rendered template
fixture.nativeElement is the real DOM element of the component's host, so querySelector returns the matching native DOM node.
In Angular testing, what is the difference between `DebugElement.query()` and `DebugElement.queryAll()`?
Answer: query() returns the first matching DebugElement; queryAll() returns an array of all matches
query() finds the first DebugElement matching a predicate (like By.css()), while queryAll() returns every matching DebugElement in the subtree.
Which Angular debugging tool lets you inspect a component's state directly from the browser's DevTools console?
Answer: ng.getComponent(element)
ng.getComponent($0) retrieves the component instance attached to the selected DOM element, allowing direct property inspection in the console.
What is the purpose of `jasmine.createSpyObj()` in Angular unit tests?
Answer: It creates a mock object with multiple named spy methods in one call
jasmine.createSpyObj('ServiceName', ['method1', 'method2']) returns an object where each listed method is already a Jasmine spy, simplifying dependency mocking.