0

I'm using Angular 6.

On running

ng test

I'm getting error like

ResetPasswordComponent should create
[object ErrorEvent] thrown

In window console, it is giving

Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'auth/login'

Error: Cannot match any routes. URL Segment: 'auth/login'
at ApplyRedirects.noMatchError (VM4374 router.js:1455)
at CatchSubscriber.eval [as selector] (VM4374 router.js:1436)
at CatchSubscriber.error (VM4260 catchError.js:40)
at MapSubscriber.Subscriber._error (VM4156 Subscriber.js:90)
at MapSubscriber.Subscriber.error (VM4156 Subscriber.js:70)
at MapSubscriber.Subscriber._error (VM4156 Subscriber.js:90)
at MapSubscriber.Subscriber.error (VM4156 Subscriber.js:70)
at MapSubscriber.Subscriber._error (VM4156 Subscriber.js:90)
at MapSubscriber.Subscriber.error (VM4156 Subscriber.js:70)
at TapSubscriber._error (VM4280 tap.js:67)
at ApplyRedirects.noMatchError (VM4374 router.js:1455)
at CatchSubscriber.eval [as selector] (VM4374 router.js:1436)
at CatchSubscriber.error (VM4260 catchError.js:40)
at MapSubscriber.Subscriber._error (VM4156 Subscriber.js:90)
at MapSubscriber.Subscriber.error (VM4156 Subscriber.js:70)
at MapSubscriber.Subscriber._error (VM4156 Subscriber.js:90)
at MapSubscriber.Subscriber.error (VM4156 Subscriber.js:70)
at MapSubscriber.Subscriber._error (VM4156 Subscriber.js:90)
at MapSubscriber.Subscriber.error (VM4156 Subscriber.js:70)
at TapSubscriber._error (VM4280 tap.js:67)
at resolvePromise (VM4143 zone.js:813)
at resolvePromise (VM4143 zone.js:770)
at eval (VM4143 zone.js:872)
at ZoneDelegate.invokeTask (VM4143 zone.js:420)
at ProxyZoneSpec.onInvokeTask (VM4148 zone-testing.js:318)
at ZoneDelegate.invokeTask (VM4143 zone.js:419)
at Object.onInvokeTask (VM4143 zone.js:298)
at ZoneDelegate.invokeTask (VM4143 zone.js:419)
at Object.onInvokeTask (VM4151 core.js:4109)
at ZoneDelegate.invokeTask (VM4143 zone.js:419)
at 

I have created auth module which has component ResetPasswordComponent.

The AuthModule is imported in auth-layout module and routing is defined in auth-layout module.

Contents of AuthModule

@NgModule({
  imports: [
    CommonModule,
    ReactiveFormsModule,
    FormsModule,
    RouterModule
  ],
  declarations: [
    LoginComponent,
    LogoutComponent,
    ForgotPasswordComponent,
    ResetPasswordComponent
  ],
  exports: [
    LoginComponent,
    ForgotPasswordComponent,
    ResetPasswordComponent,
    LogoutComponent
  ]
})
export class AuthModule { }

There is no auth/login in the component file.

the reset-password.component.html file has line

<a routerLink="/auth/login">Login</a>
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285

1 Answers1

0

This is probably irrelevant to the OP at this point, but for anyone who encounters a similar issue, and for whom none of the provided solutions for other related questions have worked or apply, I'll leave this here.

Like the OP, I had an [object ErrorEvent] thrown error in the Jasmine window, and an accompanying error in the console:

Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'members'
Error: Cannot match any routes. URL Segment: 'members'
at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError
...

Also like the OP, the path referenced in the error wasn't referenced in the spec or in the component the spec belonged to.

After several attempts to fix the error I finally decided to disable the spec. The error then moved to the next spec. So I checked the spec and component that ran immediately before the one reported as a "failure". Sure enough, in the previous component there was a reference to the path in the error, however its spec didn't register the path in the RouterTestingModule.withRoutes call.

TLDR:

If you have specs for FirstComponent, SecondComponent and ThirdComponent, but ThirdComponent fails in similar circumstances to those described above, then check SecondComponent to see if the route is referenced there. If it is, create a stub component, declare it, and add it to your RouterTestingModule.withRoutes import with the missing route. e.g.

...

describe('SecondComponent', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
RouterTestingModule.withRoutes([{path:'missing/path',component:SecondComponent}])
      ],
      declarations: [ SecondComponent ]
    })
  })

  ...

})

@Component({selector:'app-second',template:''})
class SecondComponent {}

I hope this saves someone some time. I lost hours on this, mainly because I took the failure report too literally.

Chrone
  • 21
  • 3