Is there a way to monitor and imitate a service using another service parameter? For instance, the new Authservice includes this parameter:
export class AuthService{
constructor(public serviceAbcd: ServiceAbcd) {}
This serves as an illustration without a constructor parameter on AuthService.
describe('Component: Login', () => {
let component: LoginComponent;
let service: AuthService;
let spy: any;
beforeEach(() => {
service = new AuthService();
component = new LoginComponent(service);
});
it('needsLogin returns true when the user has not been authenticated', () => {
spy = spyOn(service, 'isAuthenticated').and.returnValue(false);
expect(component.needsLogin()).toBeTruthy();
expect(service.isAuthenticated).toHaveBeenCalled();
});
afterEach(() => {
service = null;
component = null;
});
});
We are exploring testing without Testbed https://dev.to/angular/unit-testing-in-angular-to-testbed-or-not-to-testbed-3g3b