aboutsummaryrefslogtreecommitdiff
path: root/webAO/__tests__/downloadFile.test.ts
blob: 738d6f3655cf580aabd4deed8d813c299d2015ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
  });
});