-
-
Notifications
You must be signed in to change notification settings - Fork 553
/
contents-spec.js
36 lines (30 loc) · 1.09 KB
/
contents-spec.js
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
28
29
30
31
32
33
34
35
36
// @flow
jest.mock("file-saver");
import FileSaver from "file-saver";
import { stringifyNotebook } from "@nteract/commutable";
import { downloadString } from "../../src/epics/contents";
import { bigDummyJSON } from "../../src/dummy/dummy-nb";
describe("downloadString", () => {
beforeEach(() => {
FileSaver.saveAs.mockClear();
global.Blob = (content, options) => ({ content, options });
});
it("calls FileSaver.saveAs with notebook and filename", () => {
const filename = "/here/there/awesome.ipynb";
const expectedData = bigDummyJSON;
expect(FileSaver.saveAs).not.toHaveBeenCalled();
downloadString(
stringifyNotebook(bigDummyJSON),
filename,
"application/json"
);
expect(FileSaver.saveAs).toHaveBeenCalledTimes(1);
const actualMockBlobResponse = FileSaver.saveAs.mock.calls[0][0];
const actualFilename = FileSaver.saveAs.mock.calls[0][1];
expect(actualMockBlobResponse).toEqual({
content: [stringifyNotebook(expectedData)],
options: { type: "application/json" }
});
expect(actualFilename).toBe("awesome.ipynb");
});
});