0
I’m trying to test a component that uses function getCurrentNavigation()
of the Router to pick up data via navigation. My component is working normally with the expected purpose when I run with ng serve
, but my test is saying:
Component2component > should create Typeerror: this.router.getCurrentNavigation is not a Function
This is the way I get the date from the router:
constructor(public router: Router) {
if (
this.router.getCurrentNavigation() &&
this.router.getCurrentNavigation().extras
) {
console.log(this.router.getCurrentNavigation().extras);
}
My test:
describe('Component2Component', () => {
let component: Component2Component;
let fixture: ComponentFixture<Component2Component>;
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [Component2Component],
imports: [CommonModule],
providers: [{ provide: Router, useValue: routerSpy }]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(Component2Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Because my test is not recognizing this function?