I'm trying to test this function with JEST library (I'm using also enzyme in the project), but I completely stuck.
Describing this function in a few words, I use it to export previously prepared data. I machine some data and then pass it in the form of a single string, which this func wraps into a single text file and starts a download.
Mostly, it's csv, tsv and text.
/**
* Function creating text file and starting download process
*
* @param name - file name
* @param extension - file extension
* @param content - file content
*/
export const downloadTextFile = (name: string, extension: string, content: string) => {
const link = document.createElement('a');
link.className = 'download-helper';
link.download = name + '.' + extension;
link.href = `data:application/${extension},` + escape(content);
link.click();
};
I want to develop good testing habits, so I'm also trying to understand edge cases like this one here. Any tips on how to start it?