Search code examples
angularjasmineangular-test

Angular Unit testing : Error: Cannot match any routes


I Am working on unit testing under my angular 15 app. I am getting the below error while running the test:

Error: Cannot match any routes.URL Segment: 'signin'

Below is the unit test code for my component:

 fdescribe('ExtensionListComponent',()=>{
   BeforeEach(() => {
     TestBed.configureTestingModule({
       imports: [
        RouteTestingModule.withRoutes([{
        path: 'extensions-list',
       component: ExtensionListComponent}]),
       HttpClientTestingModule
       ],
       declarations:[
       ExtensionListComponent
       ],
       providers: [
       TaskService
       ]
  }).compileComponents();
 });

Solution

  • Your test is trying to navigate to login. You need to define your signin Path here:

       RouteTestingModule.withRoutes([
          {
            path: 'extensions-list',
            component: ExtensionListComponent
          },
          {
            path: 'signin',
           component: SigninComponentProbably
          }
      ]),
    

    Or fake the login access somehow.