keycloak works well in the application.
on the other hand, the unit tests with Jest I always get this error:
Cannot find module 'keycloak-angular/services/keycloak.service' from 'src/xxxxxxxxxx/services/authentification.service.ts'
Require stack:
src/xxxxxxxxxx/services/authentification.service.ts
describe('xxxxxxxxxxxxxx', () => {
...
beforeEach(() => {
TestBed.configureTestingModule({
imports: [xxxxxxxxxxxComponent, TranslateModule.forRoot()],
providers: [
provideMockStore(),
{ provide: NGXLogger, useValue: LoggerMock },
{ provide: KeycloakService, useClass: MockedKeycloakService },
AuthentificationService
]
});
fixture = TestBed.createComponent(xxxxxxxxxxxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
MockedKeycloakService
import { Injectable } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
@Injectable()
export class MockedKeycloakService extends KeycloakService {
init(): Promise<boolean> {
return Promise.resolve(true);
}
getKeycloakInstance(): any {
return {
loadUserInfo: () => {
let callback;
Promise.resolve().then(() => {
callback({
userName: 'name'
});
});
return {
success: (fn) => (callback = fn)
};
}
} as any;
}
}
AuthentificationService
public constructor(
public readonly _keycloakService: KeycloakService,
...
I also tried like this :
...
providers: [
provideMockStore(),
{ provide: NGXLogger, useValue: LoggerMock },
KeycloakService,
AuthentificationService
]
...
why it cannot find the Keycloak service even though it is well defined in providers: [ ... ]