1

I'm trying to mock router in my test. I followed the instruction step by step given in this answer but I still get error

'Cannot read property 'outlets' of null'

This is what I tried:

beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [RouterTestingModule.withRoutes([
                {path:'profile/login',component:ProfileLoginComponent}]
            )],
            declarations: [ ProfileLoginComponent ],
            providers: [
                FormBuilder,AuthModel
            ],
            schemas: [NO_ERRORS_SCHEMA]
        })
            .overrideComponent(ProfileLoginComponent, {
                set: {
                    providers: [
                        {provide: AuthModel, useClass: MockAuthModel}      
                    ],
                }
            })
            .compileComponents();
    }));

If I remove the code with routerLink and routerLinkActive in the template, then the test cases work perfectly. Where have I gone wrong?

Sanju
  • 1,478
  • 2
  • 20
  • 41

1 Answers1

0

I have managed to solved this problem. I also have answered this question in another post.

I found out this error occurs when the routerLink is pointing to a null variable. In my case, the property called favoriteUrl that i assigned to routerLink was null because of the isolated testing environment. So I manually assigned a value to the property in beforeEach function and that solved the problem, atleast for me.

Reference : https://stackoverflow.com/a/46342813/8558515

Sanju
  • 1,478
  • 2
  • 20
  • 41