-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
45 lines (37 loc) · 1.36 KB
/
index.test.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
37
38
39
40
41
42
43
44
45
const mermaidParse = require("./index");
describe("Mermaid parser", () => {
const definition = `
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F
`;
it("Should return a valid SVG if the definition is correct", async () => {
const result = await mermaidParse(definition);
// A valid SVG with ID starting with "mermaid"
expect(result.startsWith('<svg id="mermaid')).toBeTruthy();
// Test for some keywords in the definition
expect(result).toMatch(/(?=.*?\biPhone)(?=.*?\bLaptop).*/gm);
}, 120000);
it("Should return a valid SVG with error message for incorrect definition", async () => {
const definition2 = `foo`;
try {
await mermaidParse(definition2);
} catch (e) {
expect(e.message).toEqual("Syntax error in graph");
expect(e.hasOwnProperty("output")).toBeTruthy();
}
}, 120000);
describe("Should support both svg and png outputs", () => {
test("SVG", async () => {
const result = await mermaidParse(definition, { extension: "svg" });
expect(result.startsWith("<svg")).toBeTruthy();
}, 120000);
test("PNG", async () => {
const result = await mermaidParse(definition, { extension: "png" });
expect(result.startsWith("<img")).toBeTruthy();
}, 120000);
});
});