-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathformatTreeNode.spec.js
More file actions
89 lines (79 loc) · 1.92 KB
/
formatTreeNode.spec.js
File metadata and controls
89 lines (79 loc) · 1.92 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* @flow */
import formatTreeNode from './formatTreeNode';
jest.mock('./formatReactElementNode', () => () =>
'<MockedFormatReactElementNodeResult />'
);
jest.mock('./formatReactPortalNode', () => () =>
'<MockedFormatReactPortalNodeResult />'
);
describe('formatTreeNode', () => {
it('should format number tree node', () => {
expect(formatTreeNode({ type: 'number', value: 42 }, true, 0, {})).toBe(
'42'
);
});
it('should format string tree node', () => {
expect(formatTreeNode({ type: 'string', value: 'foo' }, true, 0, {})).toBe(
'foo'
);
});
it('should format react portal tree node', () => {
expect(
formatTreeNode(
{
type: 'ReactPortal',
childrens: ['abc'],
},
true,
0,
{}
)
).toBe('<MockedFormatReactPortalNodeResult />');
});
it('should format react element tree node', () => {
expect(
formatTreeNode(
{
type: 'ReactElement',
displayName: 'Foo',
},
true,
0,
{}
)
).toBe('<MockedFormatReactElementNodeResult />');
});
const jsxDelimiters = ['<', '>', '{', '}'];
jsxDelimiters.forEach(char => {
it(`should escape string that contains the JSX delimiter "${char}"`, () => {
expect(
formatTreeNode(
{ type: 'string', value: `I contain ${char}, is will be escaped` },
true,
0,
{}
)
).toBe(`{\`I contain ${char}, is will be escaped\`}`);
});
});
it('should preserve the format of string', () => {
expect(formatTreeNode({ type: 'string', value: 'foo\nbar' }, true, 0, {}))
.toBe(`foo
bar`);
expect(
formatTreeNode(
{
type: 'string',
value: JSON.stringify({ foo: 'bar' }, null, 2),
},
false,
0,
{
tabStop: 2,
}
)
).toBe(`{\`{
"foo": "bar"
}\`}`);
});
});