Bird
0
0

In a test using RouterTestingModule, what will happen if you call router.navigate(['/unknown']) where '/unknown' is not defined in routes?

medium📝 Predict Output Q5 of 15
Angular - Testing
In a test using RouterTestingModule, what will happen if you call router.navigate(['/unknown']) where '/unknown' is not defined in routes?
ARouter will redirect to the default route automatically.
BRouter will navigate to '/unknown' anyway.
CTest will throw a runtime error.
DNavigation will fail silently and location.path() remains unchanged.
Step-by-Step Solution
Solution:
  1. Step 1: Understand RouterTestingModule behavior with unknown routes

    RouterTestingModule does not throw errors for unknown routes; navigation fails silently.
  2. Step 2: Effect on location.path()

    Since navigation fails, location.path() remains at the previous route.
  3. Final Answer:

    Navigation will fail silently and location.path() remains unchanged. -> Option D
  4. Quick Check:

    Unknown route navigation = silent fail [OK]
Quick Trick: Unknown routes do not throw errors in RouterTestingModule [OK]
Common Mistakes:
  • Expecting automatic redirect to default
  • Assuming runtime error on unknown route
  • Thinking location.path() updates anyway

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes