如何在角度js中模拟茉莉花规格中的Blob和Click()

时间:2015-09-15 22:04:49

标签: angularjs unit-testing jasmine specs

如何为Blob和Click()事件编写Jasmine规范。每次我运行Specs下载文件。我可以嘲笑这个(还有浏览器)。

由于

var csvFile = "a,b,c",filename="abc.csv";

var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' });
        if (navigator.msSaveBlob) { // IE 10+
            navigator.msSaveBlob(blob, filename);
        } else {
            var link = document.createElement("a");
            if (link.download !== undefined) { // feature detection
                // Browsers that support HTML5 download attribute
                var url = URL.createObjectURL(blob);
                link.setAttribute("href", url);
                link.setAttribute("download", filename);
                link.style.visibility = 'hidden';
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
        }


describe("Should check download CSV", function() {
  it("file name should be 7 char", function() {
    expect(filename.length).toBe(7);
  });
});

});

0 个答案:

没有答案