Bird
0
0

Which of the following is the correct way to get a DebugElement for a button with CSS class submit-btn in a test fixture?

easy📝 Syntax Q12 of 15
Angular - Testing
Which of the following is the correct way to get a DebugElement for a button with CSS class submit-btn in a test fixture?
Afixture.debugElement.query(By.css('.submit-btn'))
Bfixture.getElementByClassName('submit-btn')
Cfixture.nativeElement.querySelectorAll('.submit-btn')
Dfixture.debugElement.getByClass('submit-btn')
Step-by-Step Solution
Solution:
  1. Step 1: Recall DebugElement query syntax and evaluate options

    Use fixture.debugElement.query(By.css('.submit-btn')) after initial detectChanges(). Only C matches; A returns native DOM, B/D invalid methods.
  2. Final Answer:

    fixture.debugElement.query(By.css('.submit-btn')) -> Option A
  3. Quick Check:

    Use debugElement.query with By.css [OK]
Quick Trick: Use debugElement.query(By.css()) to find elements [OK]
Common Mistakes:
  • Using nativeElement instead of debugElement for DebugElement
  • Calling non-existent methods like getByClass
  • Confusing querySelectorAll with query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes