ngx-liquid-cache
ngx-liquid-cache copied to clipboard
Cannot read property 'has' of null
TypeError: Cannot read property 'has' of null
at IndustryDataApiService.descriptor.value (D:\Development\Java\IndustryManager\node_modules\ngx-liquid-cache\bundles\ng:\ngx-liquid-cache\lib\services\liquid-cache.service.ts:165:58)
at D:\Development\Java\IndustryManager\src\app\services\industry-data-service\industry-data.service.spec.ts:132:15
Trying to write tests with LiquidCache annotation on a function is returning this error. I may be missing something in my configuration, or mocking?
IndustryDataApiService looks like this:
@Injectable()
export class IndustryDataApiService extends IndustryDataService {
constructor(
private http: HttpProvider,
private environmentConfig: EnvironmentConfigService,
private cacheService: LiquidCacheService,
private featureToggleService: FeatureToggleService,
) {
super();
}
@LiquidCache('carTypes', {duration: 300})
getAllCarTypes(): Observable<CarType[]> {
if (!this.featureToggleService.isActive('retrieveCarTypes')) {
const carTypesDataArray: CarType[] = [boxcar, flatcar];
return this.getObservable<CarType[]>(carTypesDataArray);
}
const allCarTypes = this.http.getAll<CarType>(
this.environmentConfig.carTypeGetAllApiUrl(),
);
return allCarTypes;
}
}
Test looks like this:
describe('CarType Data', () => {
const carTypesReturned: CarType[] = [boxcar, flatcar];
it('should return getAllLocations data from API', (done) => {
when(mockHttpProvider.getAll<CarType>(anyString())).thenReturn(of(carTypesReturned));
// ERROR OCCURS WHEN CALLING THE FOLLOWING LINE
service.getAllCarTypes().subscribe((response: CarType[]) => {
expect(response).toEqual(carTypesReturned);
done();
});
});
});
I can get the code working if I pass in the LiquidCacheService
and write the caching code manually, but I'd rather not.
Any ideas?