使用Angular6时,错误发生,虽然我的应用程序可以运行并且正常工作,但测试不会通过。这是文件的代码片段:
`import { Injectable } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { environment } from '../../environments/environment'
import { ICurrentWeather } from '../interfaces'
@Injectable()
export class WeatherService {
constructor(private httpClient: HttpClient) {}
getCurrentWeather(city: string, country: string): Observable<ICurrentWeather> {
return this.httpClient
.get<ICurrentWeatherData>(
`${environment.baseUrl}api.openweathermap.org/data/2.5/weather?` +
`q=${city},${country}&appid=${environment.appId}`
)
.pipe(map(data => this.transformToICurrentWeather(data)))
}
private transformToICurrentWeather(data: ICurrentWeatherData): ICurrentWeather {
return {
city: data.name,
country: data.sys.country,
date: data.dt * 1000,
image: `http://openweathermap.org/img/w/${data.weather[0].icon}.png`,
temperature: this.convertKelvinToFahrenheit(data.main.temp),
description: data.weather[0].description,
}
}
private convertKelvinToFahrenheit(kelvin: number): number {
return (kelvin * 9) / 5 - 459.67
}
}`
你没有导入ICurrentWeatherData,在接口导入中我只看到ICurrentWeather
当你替换它时,你应该导入我认为那个有效的接口:
import { ICurrentWeather } from '../interfaces'
至 :
import { ICurrentWeather } from '../interfaces/ICurrentWeather'