I have created a custom hook to display a notification message and remove it after 2 seconds. I want to write a test for this. I'm new to writing tests and not entirely sure how to write a test for this. Can anyone help me?
my hook
export function useNotification() {
const dispatch = useDispatch();
const notifications = useSelector(getNotificationsState);
function toast(type, message) {
const id = notifications.toasts.length;
const data = { type, message, id };
dispatch({
type: NOTIFICATION_ACTIONS.ADD_TOAST,
payload: data,
});
setTimeout(() => {
dispatch({
type: NOTIFICATION_ACTIONS.REMOVE_TOAST,
payload: id,
});
}, NOTIFICATION_TIMEOUT);
}
return toast;
}
I want to write the test for above hook
describe('useNotification', () => {
//Actual test
});