【发布时间】:2018-10-24 12:26:23
【问题描述】:
我正在开发一个 reactJs 应用程序。我正在使用 jest 来测试我的应用程序。 我想测试一个下载 blob 的函数。
但不幸的是,我收到了这个错误:
URL.createObjectURL 不是函数
我的测试功能:
describe('download', () => {
const documentIntial = { content: 'aaa' };
it('msSaveOrOpenBlob should not have been called when navigao is undefined', () => {
window.navigator.msSaveOrOpenBlob = null;
download(documentIntial);
expect(window.navigator.msSaveOrOpenBlob).toHaveBeenCalledTimes(0);
});
});
我要测试的功能:
export const download = document => {
const blob = new Blob([base64ToArrayBuffer(document.content)], {
type: 'application/pdf',
});
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
return;
}
const fileURL = URL.createObjectURL(blob);
window.open(fileURL);
};
【问题讨论】:
-
现在读一点你的笑话,你的问题似乎是jsdom一个。
标签: javascript reactjs testing blob jestjs