I'm trying to testing a component that uses the feature getCurrentNavigation() to get data from navigation, my component is running normally without any error when i serve it with ng serve, but my testing is saying:
Component2Component > should create TypeError: this.router.getCurrentNavigation is not a function
This is what my component do to get the data:
constructor(public router: Router) {
if (
this.router.getCurrentNavigation() &&
this.router.getCurrentNavigation().extras
) {
console.log(this.router.getCurrentNavigation().extras);
}
This is 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, RouterTestingModule],
providers: [{ provide: Router, useValue: routerSpy }]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(Component2Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Why my testing is not recognizing this function?