How to make auth0 spec file if I am using authguard implemented with auth0guard and my guard using auth0-angular

Hello,
I want to make spec.ts file if I had made my personalised authguard file (see the code below):

import { inject } from ‘@angular/core’;
import { CanActivateFn, Router } from ‘@angular/router’;
import { AuthService } from ‘@auth0/auth0-angular’;
import { catchError, map, of } from ‘rxjs’;
import { LocalizationService } from ‘@service/localization.service’;
import { AuthorizationService } from ‘@service/authorization.service’;
import { LocalizationConfig } from ‘@interface/localization-config.interface’;
import { ToastService } from ‘@shared/toast/toast.service’;
import { CONSTANTROUTES } from ‘src/constant/constantRoutes’;
export const authorizationGuard: CanActivateFn = (route, state) => {
const authService = inject(AuthService);
const localizationService = inject(LocalizationService);
const authorizationService=inject(AuthorizationService);
const toastService =inject(ToastService);
const router = inject(Router);
let routedPath:string=(“/”+CONSTANTROUTES.HOME_PATH);
let callBackPath :string = (“/”+CONSTANTROUTES.CALLBACK_PATH);

return authService.isAuthenticated$.pipe(
map((isAuthenticated) => {
if(state.url!== callBackPath){
routedPath=state.url;
}
if (isAuthenticated) {
if(state.url=== callBackPath){
router.navigate([routedPath]);
}
return true;
} else {
localizationService.getLocale().then((data:LocalizationConfig)=>{
authorizationService.loginWithRedirect(‘’,routedPath,data.lang);
})
}
return false;
}),
catchError((error) => {
console.error(‘Error resolving authentication status:’, error);
toastService.showError(error,true);
return of(false);
})
);
};

I want to make spec file for this can anyone please provide some example how to make spec file for this if i am using jest

1 Like