I am writing the simplest component that is using a routeLink:
@Component({
selector: \'memorySnippet\',
templateUrl: \'
You should have a beforeEachProviders
method looking like:
import {MockApplicationRef} from '@angular/core/testing';
beforeEachProviders(() => [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, {useValue: '/'}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: YourComponent}),
provide(ApplicationRef, {useClass: MockApplicationRef}
]);
MockApplicationRef
is provided by the framework for this kind of tests.
For RC4 with new router now use ...
beforeEach(() => addProviders([
APP_ROUTER_PROVIDERS, // must be first
{provide: APP_BASE_HREF, useValue: '/'}, // must be second
{provide: ActivatedRoute, useClass: Mock},
{provide: Router, useClass: Mock}
]));
A github project using this approach is ...
https://github.com/danday74/angular2-coverage