Reputation: 13
{
headerName: this.translateService.instant('_updated_date_'),
field: 'lastUpdateDate',
headerTooltip: this.translateService.instant('_updated_date_'),
valueFormatter: (params: any) => params?.value ? this.utilService.dateFormatter(params.value, TmLinkConstants.DATE_FORMAT) : '',
minWidth: 120,
tooltipValueGetter: (params: any) => params?.value ? this.utilService.dateFormatter(params.value, TmLinkConstants.DATE_FORMAT) : ''
}
Tried to write coverage this but doesnt seem to take any.
Upvotes: 1
Views: 30
Reputation: 58199
First convert them to their own individual functions
const valueFormatter = (params: any) => params?.value ? this.utilService.dateFormatter(params.value, TmLinkConstants.DATE_FORMAT) : '';
const tooltipValueGetter = (params: any) => params?.value ? this.utilService.dateFormatter(params.value, TmLinkConstants.DATE_FORMAT) : '';
...
...
{
headerName: this.translateService.instant('_updated_date_'),
field: 'lastUpdateDate',
headerTooltip: this.translateService.instant('_updated_date_'),
valueFormatter: valueFormatter,
minWidth: 120,
tooltipValueGetter: tooltipValueGetter,
}
...
Then coverage becomes simple
desc('valueFormatter', () => {
it('should return value', () => {
spyOn(utilService, 'dateFormatter').and.returnValue('TEST');
expect(valueFormatter({value: 'test'})).toEqual('TEST');
})
});
desc('tooltipValueGetter', () => {
it('should return value', () => {
spyOn(utilService, 'dateFormatter').and.returnValue('TEST');
expect(tooltipValueGetter({value: 'test'})).toEqual('TEST');
})
});
Upvotes: 0