Hi I am trying to write angular code for a component with an observable but I can't test the broadcast service. I get an error saying the service is not being called. How Should I access the service? Any help would be appreciated. Thank you.
This is my component with the observable:
ngOnInit(): void {
this.subscription.add(
this.broadcastService.subscribe('msal:acquireTokenSuccess', (payload) => {
// do something here
this.roleService.checkServerEventReviewers().subscribe(res => {
this.userService.userDetails.role = res ? 'Data Steward' : 'Mosaic Consumer';
if (this.isLoggedIn !== true) {
const redirectUri = sessionStorage.getItem('redirectUri');
if (redirectUri !== undefined || redirectUri !== null) {
this.router.navigateByUrl(redirectUri);
}
}
this.isLoggedIn = true;
};
This is my spec file that I am trying:
describe(':', () => {
function setup() {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
const compiled = fixture.debugElement.nativeElement;
return {fixture, app, compiled};
}
it('Init with QA environment', () => {
const {app} = setup();
spyOn(app.authService, 'getUser').and.returnValue(mockData.userDetails);
spyOn(app.authService, 'acquireTokenSilent').and.returnValue('msal:acquireTokenSuccess');
app.ngOnInit();
spyOn(app.broadcastService,'subscribe');
expect(app.broadcastService.subscribe).toHaveBeenCalled();
);
Aucun commentaire:
Enregistrer un commentaire