Bird
0
0

Which of the following is the correct way to declare a component in TestBed configuration?

easy📝 Syntax Q12 of 15
Angular - Testing
Which of the following is the correct way to declare a component in TestBed configuration?
ATestBed.configureTestingModule({ imports: [MyComponent] })
BTestBed.configureTestingModule({ bootstrap: [MyComponent] })
CTestBed.configureTestingModule({ providers: [MyComponent] })
DTestBed.configureTestingModule({ declarations: [MyComponent] })
Step-by-Step Solution
Solution:
  1. Step 1: Identify where components go in TestBed

    Components must be listed under declarations in the configuration.
  2. Step 2: Check each option

    Only TestBed.configureTestingModule({ declarations: [MyComponent] }) uses declarations with the component. Others misuse imports, providers, or bootstrap.
  3. Final Answer:

    TestBed.configureTestingModule({ declarations: [MyComponent] }) -> Option D
  4. Quick Check:

    Components go in declarations [OK]
Quick Trick: Components go in declarations, modules in imports, services in providers [OK]
Common Mistakes:
  • Putting components inside imports or providers
  • Using bootstrap in TestBed config (only for app modules)
  • Forgetting to declare components causes errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes