Import the NavController module from ionic-angular.
import { NavController } from 'ionic-angular';
Add NavController to the providers array and swap it out for a mock NavController.
providers: [
{ provide: NavController, useValue: mockNavController }
]
Add the mockNavController value.
let mockNavController = {
setRoot: {
}
};
Add the spy within the beforeEach().
beforeEach( async( () => {
spyOn( mockNavController, 'setRoot' ).and.callFake( function () {
return true;
});
}));
You can then spy on the setRoot event.
expect( mockNavController.setRoot ).toHaveBeenCalled();