Я хочу протестировать эту простую охрану как canActivate, так и canLoad. Как с ней справиться?Я сделал свой первый шаг, управляя введенным хранилищем
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate, CanLoad {
constructor(private store: Store<AuthState>) {}
canActivate(): Observable<boolean> {
return this.store.pipe(
select(selectIsAuthenticated),
map(isValidToken => {
if (!isValidToken) {
this.store.dispatch(new Logout());
return false;
}
return true;
}),
take(1)
);
}
canLoad(): Observable<boolean> {
return this.store.pipe(
select(selectIsAuthenticated),
map(isValidToken => {
if (!isValidToken) {
this.store.dispatch(new Logout());
return false;
}
return true;
}),
take(1)
);
}
}
Мой первый шаг
export const authReducer: ActionReducerMap<{}> = {
status: {}
};
describe('AuthGuard', () => {
let store: Store<{}>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [StoreModule.forRoot({}).forFeature('auth', authReducer)],
providers: [Store, AuthGuard]
});
store = TestBed.get(Store);
});
it('should ...', inject([AuthGuard], (guard: AuthGuard) => {
expect(guard).toBeTruthy();
}));
});
Но как насчет тестирования canActivate и canLoad?Я должен издеваться над выбором и как?