โ† All Angular Web Framework Flashcard Decks

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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.