aboutsummaryrefslogtreecommitdiff
path: root/webAO/__tests__/downloadFile.test.ts
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2025-06-26 18:49:00 +0200
committerstonedDiscord <Tukz@gmx.de>2025-06-26 18:49:00 +0200
commitd31b1aaa22a71cd9e9f0949036cec5facb515616 (patch)
treed806ae7d3add55cace2f4ce665130ac971319229 /webAO/__tests__/downloadFile.test.ts
parent7effd0f458663f5af821fb96b0dd23ef32b43e43 (diff)
move tests
Diffstat (limited to 'webAO/__tests__/downloadFile.test.ts')
-rw-r--r--webAO/__tests__/downloadFile.test.ts27
1 files changed, 27 insertions, 0 deletions
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 <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);
+ });
+});