-
Notifications
You must be signed in to change notification settings - Fork 8
/
replaceMdSection.test.mjs
95 lines (81 loc) · 1.95 KB
/
replaceMdSection.test.mjs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { strictEqual, throws } from "assert";
import replaceMdSection from "./replaceMdSection.mjs";
export default (tests) => {
tests.add(
"`replaceMdSection` with argument 1 `markdown` not a string.",
() => {
throws(
() => replaceMdSection(true),
new TypeError("Argument 1 `markdown` must be a string.")
);
}
);
tests.add(
"`replaceMdSection` with argument 1 `markdown` not a populated string.",
() => {
throws(
() => replaceMdSection(""),
new TypeError("Argument 1 `markdown` must be a populated string.")
);
}
);
tests.add(
"`replaceMdSection` with argument 2 `targetHeading` not a string.",
() => {
throws(
() => replaceMdSection("a", true),
new TypeError("Argument 2 `targetHeading` must be a string.")
);
}
);
tests.add(
"`replaceMdSection` with argument 2 `targetHeading` not a populated string.",
() => {
throws(
() => replaceMdSection("a", ""),
new TypeError("Argument 2 `targetHeading` must be a populated string.")
);
}
);
tests.add(
"`replaceMdSection` with argument 3 `replacementMdAst` not an object.",
() => {
throws(
() => replaceMdSection("a", "a", true),
new TypeError("Argument 3 `replacementMdAst` must be an object.")
);
}
);
tests.add("`replaceMdSection` with the target heading present.", () => {
const targetHeading = "Target";
strictEqual(
replaceMdSection(
`# Preserve
## ${targetHeading}
Replace.
## Preserve
`,
targetHeading,
{
type: "root",
children: [
{
type: "paragraph",
children: [
{
type: "text",
value: "Replaced.",
},
],
},
],
}
),
`# Preserve
## ${targetHeading}
Replaced.
## Preserve
`
);
});
};