-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathunist.test.mjs
More file actions
72 lines (68 loc) · 1.58 KB
/
unist.test.mjs
File metadata and controls
72 lines (68 loc) · 1.58 KB
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
import { strictEqual } from 'node:assert';
import { describe, it } from 'node:test';
import { transformNodesToString, callIfBefore } from '../unist.mjs';
describe('transformNodesToString', () => {
it('should transform a list of Nodes into a string', () => {
const nodes = [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'Hello, ',
},
{
type: 'strong',
children: [
{
type: 'text',
value: 'World',
},
],
},
],
},
];
strictEqual(transformNodesToString(nodes), 'Hello, **World**');
});
});
describe('callIfBefore', () => {
it('should call the callback if the first Node is before the second Node', () => {
const nodeA = {
position: {
start: {
line: 1,
},
},
};
const nodeB = {
position: {
start: {
line: 2,
},
},
};
callIfBefore(nodeA, nodeB, (nodeA, nodeB) => {
strictEqual(nodeA.position.start.line < nodeB.position.start.line, true);
});
});
it('should not call the callback if the first Node is not before the second Node', () => {
const nodeA = {
position: {
start: {
line: 2,
},
},
};
const nodeB = {
position: {
start: {
line: 1,
},
},
};
callIfBefore(nodeA, nodeB, (nodeA, nodeB) => {
strictEqual(nodeA.position.start.line < nodeB.position.start.line, true);
});
});
});