I'm currently trying to test a function using the JEST library (I also have enzyme in my project), but I've hit a wall.
To summarize, this function is used to export data that has been prepared beforehand. I manipulate some data and then pass it as a single string to this function, which packages it into a text file for download purposes.
Mainly, the exported formats are csv, tsv, and plain text files.
/**
* Function that generates a text file and initiates the 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 aim to cultivate good testing practices, so understanding scenarios like this one is crucial. Any advice on how to approach testing edge cases?
👋