I have this function
1:
function OnRangeChange(elementID) {
const element = document.getElementById(elementID);
const queryName = element.getAttribute('data-technicalname');
element.noUiSlider.on('change', (values, handle) => {
$(`.range-reset.${queryName}`).removeClass('hidden');
fetchProductsOnRangeChange(values, element);
});
}
// And a unit test
test('should fetch new products on rangeSlider change using OnRangeChange', () => {
const elementID = 'twobuttons-range_0';
window.twoButtonsRangeSliderComponent.OnRangeChange(elementID)
expect($(`.range-reset.laenge`).hasClass('disabled')).toBeFalsy();
});
2:
function fetchProductsOnRangeChange(values, element) {
// on Range Slider change trigger a new ajax and call renderFilterResults to render new products and all filter settings
let queryName = element.getAttribute('data-technicalname'),
unit = element.getAttribute('data-unit'),
queryValue = `${values[0]}${unit}-${values[1]}${unit}`;
window.ZEP.ProductFilter.onSelectionClick(queryName, queryValue, 'single');
window.ZEP.ProductFilter.getFilterDataByParameters(function(error, data) {
if (!error) {
$('.product-list-wrapper').text(data)
} else {
$('.product-list-wrapper').empty();
$('.product-list-wrapper').text(`Ajax call failed- ${error.status}:${error.statusText}`);
}
});
}
which calls a callback function on the noUiSlider change event. I have written a unit test to test the function OnRangeChange, but the callback function for the on change event is not covered by jest test coverage. The same happens for the 2 function I have added the getFilterDataByParameters callback is highlighted red as not covered . How do I get jest to cover the callback function of the on change event?