I have a simple router guard and I am trying to test the canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot )
. I can create the ActivatedRouteSn
Based on a previous question I had about Router I tried this...
let mockSnapshot: any;
...
mockSnapshot = jasmine.createSpyObj("RouterStateSnapshot", ['toString']);
...
TestBed.configureTestingModule({
imports: [RouterTestingModule],
providers:[
{provide: RouterStateSnapshot, useValue: mockSnapshot}
]
}).compileComponents();
...
let test = guard.canActivate(
new ActivatedRouteSnapshot(),
TestBed.get(RouterStateSnapshot)
);
The problem I now have is that I need the toString here mockSnapshot = jasmine.createSpyObj("RouterStateSnapshot", ['toString']);
. This is because jasmine createSpyObj requires at least one mocked method. Since I am not testing the side effects of RouterStateSnapshot, this seems like extra work for nothing.