diff options
Diffstat (limited to 'webAO/services')
| -rw-r--r-- | webAO/services/__tests__/downloadFile.test.ts | 48 | ||||
| -rw-r--r-- | webAO/services/downloadFile.ts | 14 |
2 files changed, 31 insertions, 31 deletions
diff --git a/webAO/services/__tests__/downloadFile.test.ts b/webAO/services/__tests__/downloadFile.test.ts index b541095..c37c735 100644 --- a/webAO/services/__tests__/downloadFile.test.ts +++ b/webAO/services/__tests__/downloadFile.test.ts @@ -1,27 +1,27 @@ -import downloadFile from '../downloadFile' -jest - .useFakeTimers() - .setSystemTime(new Date('2020-01-01').getTime()); +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})} +(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 +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); + }); +}); diff --git a/webAO/services/downloadFile.ts b/webAO/services/downloadFile.ts index d272249..5b2f292 100644 --- a/webAO/services/downloadFile.ts +++ b/webAO/services/downloadFile.ts @@ -1,8 +1,8 @@ const downloadFile = (content: string, filename: string) => { - const a = document.createElement('a'); - const file = new Blob([content], { type: 'text' }); - a.href = URL.createObjectURL(file); - a.download = filename; - a.click(); -} -export default downloadFile + const a = document.createElement("a"); + const file = new Blob([content], { type: "text" }); + a.href = URL.createObjectURL(file); + a.download = filename; + a.click(); +}; +export default downloadFile; |
