Here is the file that I need to test. My current focus is on some effects service while working with Angular5 (^5.2.0) and ngrx5 (^5.2.0). I have been struggling to properly implement the code below for testing purposes. Any tips or suggestions would be greatly appreciated. Thank you!
import { Injectable } from '@angular/core';
import { Actions, Effect } from '@ngrx/effects';
import { FETCH_DATA } from '../reducers/data.reducer';
import { DataService } from './data.service';
import { Subject } from 'rxjs/Subject';
import { ActionWithPayload } from '../types/app-actions';
@Injectable()
export class AutoCompleteEffects {
public autoComplete$ = new Subject<{
type: string;
payload: { results: string[]; searchValue: string };
}>();
@Effect()
getData$ = this.actions$.ofType(FETCH_DATA).switchMap((action: ActionWithPayload) => {
return this.data
.getData(action.payload)
.map(results => ({
type: 'FETCHED_DATA',
payload: { results, searchValue: action.payload }
}))
.catch(() =>
Observable.of({
type: 'FETCHED_DATA',
payload: { results: [], searchValue: action.payload }
})
);
});
constructor(
private actions$: Actions,
private data: DataService,
) {
this.getData$.subscribe(action => this.autoComplete$.next(action));
}
public getAutoCompleteEffects() {
return this.autoComplete$.asObservable();
}
}