From d31b1aaa22a71cd9e9f0949036cec5facb515616 Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Thu, 26 Jun 2025 18:49:00 +0200 Subject: move tests --- webAO/__tests__/downloadFile.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 webAO/__tests__/downloadFile.test.ts (limited to 'webAO/__tests__/downloadFile.test.ts') diff --git a/webAO/__tests__/downloadFile.test.ts b/webAO/__tests__/downloadFile.test.ts new file mode 100644 index 0000000..738d6f3 --- /dev/null +++ b/webAO/__tests__/downloadFile.test.ts @@ -0,0 +1,27 @@ +import downloadFile from "../services/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 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); + }); +}); -- cgit