I tried a lot of ways but i failed to know a way to run jest tests on code like that
const geoNamesData = async (url, destination, api) => {
const response = await fetch(url + destination + api);
try {
const data = await response.json();
//console.log(data.geonames[0]);
return data.geonames[0];
} catch (error) {
console.error(error);
}
};
export default geoNamesData;
or just simple function expression like that
here i try to run this code but it always failed
import {daysRemaining } from './daysRemaining'
describe('the function "daysRemaining" should exist' , () => {
test('It should return true', () => {
expect(daysRemaining).toBeDefined();
});
});
describe('the function "daysRemaining()" should be a function' , () => {
test('It should be a function', () => {
expect(typeof daysRemaining).toBe("function");
});
});
and my javascript code is
export default function daysRemaining() {
const today = new Date(); //today date
const tripDate = new Date(document.getElementById('date').value); //trip date entered by user
if (tripDate > today) {
const isRemaining = Math.ceil(
Math.abs(tripDate - today) / (1000 * 60 * 60 * 24)
);
//console.log(isRemaining);
return !!isRemaining;
}
return false;
}
so please how could I run jest tests on functions like previous one