Skip to content

Commit 622864d

Browse files
committed
Preserve line break
1 parent 99d2786 commit 622864d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/parser/parseReactElement.spec.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { Fragment } from 'react';
22
import parseReactElement from './parseReactElement';
3+
34
const options = {};
5+
46
describe('parseReactElement', () => {
57
it('should parse a react element with a string as children', () => {
68
expect(parseReactElement(<h1>Hello world</h1>, options)).toEqual({
@@ -16,6 +18,7 @@ describe('parseReactElement', () => {
1618
],
1719
});
1820
});
21+
1922
it('should filter empty childrens', () => {
2023
expect(
2124
parseReactElement(
@@ -46,6 +49,7 @@ describe('parseReactElement', () => {
4649
],
4750
});
4851
});
52+
4953
it('should parse a single depth react element', () => {
5054
expect(parseReactElement(<aaa foo="41" />, options)).toEqual({
5155
type: 'ReactElement',
@@ -57,6 +61,7 @@ describe('parseReactElement', () => {
5761
childrens: [],
5862
});
5963
});
64+
6065
it('should parse a react element with an object as props', () => {
6166
expect(
6267
parseReactElement(
@@ -85,6 +90,7 @@ describe('parseReactElement', () => {
8590
childrens: [],
8691
});
8792
});
93+
8894
it('should parse a react element with another react element as props', () => {
8995
expect(parseReactElement(<div a={<span b="42" />} />, options)).toEqual({
9096
type: 'ReactElement',
@@ -96,13 +102,14 @@ describe('parseReactElement', () => {
96102
childrens: [],
97103
});
98104
});
105+
99106
it('should parse the react element defaultProps', () => {
100107
const Foo = () => {};
101-
102108
Foo.defaultProps = {
103109
bar: 'Hello Bar!',
104110
baz: 'Hello Baz!',
105111
};
112+
106113
expect(
107114
parseReactElement(<Foo foo="Hello Foo!" bar="Hello world!" />, options)
108115
).toEqual({
@@ -120,6 +127,7 @@ describe('parseReactElement', () => {
120127
childrens: [],
121128
});
122129
});
130+
123131
it('should extract the component key', () => {
124132
expect(parseReactElement(<div key="foo-1" />, options)).toEqual({
125133
type: 'ReactElement',
@@ -131,6 +139,7 @@ describe('parseReactElement', () => {
131139
childrens: [],
132140
});
133141
});
142+
134143
it('should extract the component ref', () => {
135144
const refFn = () => 'foo';
136145

@@ -143,6 +152,7 @@ describe('parseReactElement', () => {
143152
},
144153
childrens: [],
145154
});
155+
146156
// eslint-disable-next-line react/no-string-refs
147157
expect(parseReactElement(<div ref="foo" />, options)).toEqual({
148158
type: 'ReactElement',
@@ -154,6 +164,7 @@ describe('parseReactElement', () => {
154164
childrens: [],
155165
});
156166
});
167+
157168
it('should parse a react fragment', () => {
158169
expect(
159170
parseReactElement(

src/tree.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createReactElementTreeNode,
55
createReactFragmentTreeNode,
66
} from './tree';
7+
78
describe('createStringTreeNode', () => {
89
it('generate a string typed node payload', () => {
910
expect(createStringTreeNode('foo')).toEqual({
@@ -12,6 +13,7 @@ describe('createStringTreeNode', () => {
1213
});
1314
});
1415
});
16+
1517
describe('createNumberTreeNode', () => {
1618
it('generate a number typed node payload', () => {
1719
expect(createNumberTreeNode(42)).toEqual({
@@ -20,6 +22,7 @@ describe('createNumberTreeNode', () => {
2022
});
2123
});
2224
});
25+
2326
describe('createReactElementTreeNode', () => {
2427
it('generate a react element typed node payload', () => {
2528
expect(
@@ -46,6 +49,7 @@ describe('createReactElementTreeNode', () => {
4649
});
4750
});
4851
});
52+
4953
describe('createReactFragmentTreeNode', () => {
5054
it('generate a react fragment typed node payload', () => {
5155
expect(createReactFragmentTreeNode('foo', ['abc'])).toEqual({

src/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable no-use-before-define */
2+
23
import type { Key } from 'react';
34

45
type PropsType = Record<string, any>;
5-
66
type DefaultPropsType = Record<string, any>;
77

88
export type StringTreeNode = {

0 commit comments

Comments
 (0)