diff options
| author | stonedDiscord <Tukz@gmx.de> | 2022-03-28 23:41:56 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2022-03-28 23:41:56 +0200 |
| commit | 903a13ff5b5beaaf42b4fcf8965eb55b642e1d2a (patch) | |
| tree | 7e7cbf09c1ce6d2539bb2f33a9c3c86f19ce9d48 /webAO/services/__tests__/downloadFile.test.ts | |
| parent | 06ee582c4adefdb35220c63ee4a30444474e9388 (diff) | |
| parent | d3911aa9ad6bc16c70355fe11d1377d636b14565 (diff) | |
Merge branch 'master' into coolloading
Diffstat (limited to 'webAO/services/__tests__/downloadFile.test.ts')
| -rw-r--r-- | webAO/services/__tests__/downloadFile.test.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/webAO/services/__tests__/downloadFile.test.ts b/webAO/services/__tests__/downloadFile.test.ts new file mode 100644 index 0000000..b217b2c --- /dev/null +++ b/webAO/services/__tests__/downloadFile.test.ts @@ -0,0 +1,27 @@ +import downloadFile from '../downloadFile' +jest + .useFakeTimers() + .setSystemTime(new Date('2020-01-01').getTime()); + + global.URL.createObjectURL = jest.fn(); +(window as any).global.Blob = function (content, options){return ({content, options})} + +describe('downloadFile', () => { + it('Creates an <a> tag', () => { + const createElementSpy = jest.spyOn(document, 'createElement'); + downloadFile('hi', 'filename') + expect(createElementSpy).toBeCalled() + }) + it('Creates the blob with the correct data', () => { + const data = 'writingtestsishard' + global.URL.createObjectURL = jest.fn(() => data); + downloadFile(data, 'filename') + const expected = { + content: [data], + options: { + type: "text" + } + } + expect(global.URL.createObjectURL).toBeCalledWith(expected) + }) +})
\ No newline at end of file |
