lundi 25 novembre 2019

How can I test this Observable function in angular 7

I got this function and I need to test, I don't know what to do!

public flightStream(prefix: AvaliableHttpPrefix, url: string, headers: any, body?: any): Observable<FlightData[] | FlightData> {
    return timer(GENERAL_CONSTANTS.FLIGHTS_INITIAL_DELAY, GENERAL_CONSTANTS.FLIGHTS_REFRESH_TIME)
      .pipe(
        flatMap(_ => {
          return this.httpHandlerService.request(prefix, url, headers, body)
        }),
        map(response => {
          if (Array.isArray(response)) {
            console.log(response);
            return response as FlightData[]
          }
          return response as FlightData
        })
      )
  }

I try to make this

it('should call get function and return a list of flights', () => {
    const flightsService: FlightsService = TestBed.get(FlightsService);
    const stream$ = flightsService.flightStream(flightListStreamMock.prefix, flightListStreamMock.URL, flightListStreamMock.headers, flightListStreamMock.filterCriteria);
    stream$.subscribe((result) => {
      expect(result).toBe(FLIGHTS)
    })
  })

But it says Timeout - Async callback was not invoked within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)

Aucun commentaire:

Enregistrer un commentaire