简体   繁体   中英

Using rxjs timer and observable to substitute http server

I have an observable for my search input, I'd like to test it with a timer or setTimeout rather than using a server.

this.definitions = this.searchInput.valueChanges
                        .pipe(
                          startWith(''),
                          debounceTime(500),
                          distinctUntilChanged(),
                          switchMap(value => this.definitionService.searchTerm(value))
                        )

How can I return observable with timed next() values in my search service to test the input subscription? I'd like to generate responses x seconds.

searchTerm(term: string): Observable<Array<any>>
const searchTerm = (term: string): Observable<Array<any>> =>
  Rx.interval(1e3).pipe(map(() => generateFakeResult(term))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM