I have the following code...
export class LoginComponent {
userName: string;
password: string;
rememberMe: boolean = false;
constructor( private auth: AuthenticationService,
private router: Router) {
...
}
...
}
I am trying to Unit test but my first attempt failed....
beforeEach(() => {
router = new Router();
component = new LoginComponent(authService, router);
});
Because it needs the params for the Router constructor. Here I saw...
beforeEach(() => addProviders([
APP_ROUTER_PROVIDERS, // must be first
{provide: APP_BASE_HREF, useValue: '/'}, // must be second
{provide: ActivatedRoute, useClass: Mock},
{provide: Router, useClass: Mock}
]));
But I don't seem to have APP_ROUTER_PROVIDERS
or Mock
anywhere in my dependencies, so I think it might be stale (or I need dependencies).
How do I mock this out? It doesn't even matter for the test I am working on.
TestBed.configureTestingModule({imports: [RouterTestingModule]});
androuter = TestBed.get(Router);
? I haven't tested it yet though so I am not sure it works. – Cow