Testing function that starts file download with jest

问题: 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 e...

问题:

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?

  • 发表于 2019-03-07 13:20
  • 阅读 ( 175 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除