I have an Angular 6 app that has an export to CSV button that when clicked, runs a method on the component that generates the CSV text to be downloaded. The file is then downloaded with the following code:
const tempLink = document.createElement('a');
tempLink.href = 'data:text/csv;charset=utf-8,' + encodeURI(csvContent);
tempLink.target = '_blank';
tempLink.download = 'export.csv';
tempLink.click();
How would I unit test clicking the Export to CSV button without triggering an actual download?
Would the only approach be to create the link in the HTML (not dynamically) and then have a Jasmine spy on the click event of the link?