@@ -14,7 +14,7 @@ const docWrapper = (children: any) => {
14
14
}
15
15
}
16
16
const compareValue = ( json1 , json2 ) => {
17
- return isEqual ( JSON . stringify ( omitdeep ( json1 , "uid" ) ) , JSON . stringify ( omitdeep ( docWrapper ( json2 ) , "uid" ) ) )
17
+ return expect ( JSON . stringify ( omitdeep ( json1 , "uid" ) ) ) . toEqual ( JSON . stringify ( omitdeep ( docWrapper ( json2 ) , "uid" ) ) ) ;
18
18
}
19
19
20
20
jest . mock ( 'uuid' , ( ) => ( { v4 : ( ) => 'uid' } ) ) ;
@@ -24,66 +24,62 @@ describe("Testing html to json conversion", () => {
24
24
const dom = new JSDOM ( html )
25
25
let htmlDoc = dom . window . document . querySelector ( 'body' )
26
26
let jsonValue = fromRedactor ( htmlDoc )
27
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , docWrapper ( [ { "attrs" : { } , "children" : [ { "text" : "This is test" } ] , "type" : "p" } ] ) )
28
- expect ( testResult ) . toBe ( true )
27
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( docWrapper ( [ { "attrs" : { } , "children" : [ { "text" : "This is test" } ] , "type" : "p" } ] ) ) ;
28
+
29
29
} )
30
30
31
31
it ( "heading conversion" , ( ) => {
32
32
let html = expectedValue [ 2 ] . html
33
33
const dom = new JSDOM ( html )
34
34
let htmlDoc = dom . window . document . querySelector ( 'body' )
35
35
let jsonValue = fromRedactor ( htmlDoc )
36
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 2 ] . json ) , "uid" ) )
37
- expect ( testResult ) . toBe ( true )
36
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 2 ] . json ) , "uid" ) ) ;
37
+
38
38
} )
39
39
it ( "table conversion" , ( ) => {
40
40
let html = expectedValue [ 3 ] . html
41
41
const dom = new JSDOM ( html )
42
42
let htmlDoc = dom . window . document . querySelector ( 'body' )
43
43
let jsonValue = fromRedactor ( htmlDoc )
44
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 3 ] . json ) , "uid" ) )
45
- expect ( testResult ) . toBe ( true )
44
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 3 ] . json ) , "uid" ) ) ;
45
+
46
46
} )
47
47
it ( "basic formating, block and code conversion" , ( ) => {
48
48
let html = expectedValue [ 4 ] . html
49
49
const dom = new JSDOM ( html )
50
50
let htmlDoc = dom . window . document . querySelector ( 'body' )
51
51
let jsonValue = fromRedactor ( htmlDoc )
52
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 4 ] . json ) , "uid" ) )
53
- expect ( testResult ) . toBe ( true )
52
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 4 ] . json ) , "uid" ) ) ;
53
+
54
54
} )
55
55
it ( "List and alignment conversion" , ( ) => {
56
56
let html = expectedValue [ 5 ] . html
57
57
const dom = new JSDOM ( html )
58
58
let htmlDoc = dom . window . document . querySelector ( 'body' )
59
59
let jsonValue = fromRedactor ( htmlDoc )
60
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 5 ] . json ) , "uid" ) )
61
- expect ( testResult ) . toBe ( true )
60
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 5 ] . json ) , "uid" ) ) ;
62
61
} )
63
62
it ( "Link ,divider and property conversion" , ( ) => {
64
63
let html = expectedValue [ 7 ] . html
65
64
const dom = new JSDOM ( html )
66
65
let htmlDoc = dom . window . document . querySelector ( 'body' )
67
66
let jsonValue = fromRedactor ( htmlDoc )
68
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 7 ] . json ) , "uid" ) )
69
- expect ( testResult ) . toBe ( true )
67
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 7 ] . json ) , "uid" ) ) ;
70
68
} )
71
69
72
70
it ( "Embedded entry as link" , ( ) => {
73
71
let html = expectedValue [ 8 ] . html
74
72
const dom = new JSDOM ( html )
75
73
let htmlDoc = dom . window . document . querySelector ( 'body' )
76
74
let jsonValue = fromRedactor ( htmlDoc )
77
- let testResult = isEqual ( JSON . stringify ( omitdeep ( jsonValue , "uid" ) , null , 2 ) , JSON . stringify ( omitdeep ( docWrapper ( expectedValue [ 8 ] . json ) , "uid" ) , null , 2 ) )
78
- expect ( testResult ) . toBe ( true )
75
+ expect ( JSON . stringify ( omitdeep ( jsonValue , "uid" ) , null , 2 ) ) . toStrictEqual ( JSON . stringify ( omitdeep ( docWrapper ( expectedValue [ 8 ] . json ) , "uid" ) , null , 2 ) ) ;
79
76
} )
80
77
it ( "Embedded entry as inline block" , ( ) => {
81
78
let html = expectedValue [ 9 ] . html
82
79
const dom = new JSDOM ( html )
83
80
let htmlDoc = dom . window . document . querySelector ( 'body' )
84
81
let jsonValue = fromRedactor ( htmlDoc )
85
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 9 ] . json ) , "uid" ) )
86
- expect ( testResult ) . toBe ( true )
82
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 9 ] . json ) , "uid" ) ) ;
87
83
} )
88
84
89
85
it ( "Embedded entry as block" , ( ) => {
@@ -92,8 +88,7 @@ describe("Testing html to json conversion", () => {
92
88
let htmlDoc = dom . window . document . querySelector ( 'body' )
93
89
94
90
let jsonValue = fromRedactor ( htmlDoc )
95
- let testResult = isEqual ( omitdeep ( jsonValue , "uid" ) , omitdeep ( docWrapper ( expectedValue [ 10 ] . json ) , "uid" ) )
96
- expect ( testResult ) . toBe ( true )
91
+ expect ( omitdeep ( jsonValue , "uid" ) ) . toStrictEqual ( omitdeep ( docWrapper ( expectedValue [ 10 ] . json ) , "uid" ) ) ;
97
92
} )
98
93
99
94
it ( "Basic Scenarios" , ( ) => {
@@ -104,12 +99,7 @@ describe("Testing html to json conversion", () => {
104
99
let htmlDoc = dom . window . document . querySelector ( 'body' )
105
100
let jsonValue = fromRedactor ( htmlDoc )
106
101
//console.log(JSON.stringify(omitdeep(jsonValue.children, "uid"), null, 2))
107
- let testResult = compareValue ( jsonValue , expectedValue [ index ] . json )
108
- if ( ! testResult ) {
109
- //console.log(JSON.stringify(omitdeep(jsonValue, "uid")))
110
- //console.log(JSON.stringify(omitdeep(expectedValue[index].json, "uid")))
111
- }
112
- expect ( testResult ) . toBe ( true )
102
+ compareValue ( jsonValue , expectedValue [ index ] . json )
113
103
} )
114
104
} )
115
105
it ( "Custom ELEMENT_TAGS" , ( ) => {
@@ -120,8 +110,7 @@ describe("Testing html to json conversion", () => {
120
110
let htmlDoc = dom . window . document . querySelector ( 'body' )
121
111
let jsonValue = fromRedactor ( htmlDoc , { customElementTags :expectedValue [ index ] . customElementTags } )
122
112
//console.log(JSON.stringify(omitdeep(jsonValue.children, "uid"), null, 2))
123
- let testResult = compareValue ( jsonValue , expectedValue [ index ] . json )
124
- expect ( testResult ) . toBe ( true )
113
+ compareValue ( jsonValue , expectedValue [ index ] . json )
125
114
} )
126
115
} )
127
116
it ( "Custom TEXT_TAGS" , ( ) => {
@@ -132,8 +121,7 @@ describe("Testing html to json conversion", () => {
132
121
let htmlDoc = dom . window . document . querySelector ( 'body' )
133
122
let jsonValue = fromRedactor ( htmlDoc , { customTextTags :expectedValue [ index ] . customTextTags } )
134
123
//console.log(JSON.stringify(omitdeep(jsonValue.children, "uid"), null, 2))
135
- let testResult = compareValue ( jsonValue , expectedValue [ index ] . json )
136
- expect ( testResult ) . toBe ( true )
124
+ compareValue ( jsonValue , expectedValue [ index ] . json )
137
125
} )
138
126
} )
139
127
it ( "Conversion with allowNonStandardTags" , ( ) => {
@@ -145,12 +133,7 @@ describe("Testing html to json conversion", () => {
145
133
const dom = new JSDOM ( html )
146
134
let htmlDoc = dom . window . document . querySelector ( 'body' )
147
135
let jsonValue = fromRedactor ( htmlDoc , { allowNonStandardTags :true , customTextTags :expectedValue [ index ] . customTextTags } )
148
- let testResult = compareValue ( jsonValue , expectedValue [ index ] . json )
149
- if ( ! testResult ) {
150
- //console.log(JSON.stringify(omitdeep(jsonValue, "uid")))
151
- //console.log(JSON.stringify(omitdeep(expectedValue[index].json, "uid")))
152
- }
153
- expect ( testResult ) . toBe ( true )
136
+ compareValue ( jsonValue , expectedValue [ index ] . json )
154
137
expect ( mockFunction ) . toHaveBeenCalledTimes ( expectedValue [ index ] . nonStandardTags )
155
138
} )
156
139
} )
@@ -372,14 +355,9 @@ describe("CS-41001", () =>{
372
355
} )
373
356
} )
374
357
375
-
376
-
377
-
378
-
379
358
function htmlToJson ( html : string , options : IHtmlToJsonOptions ) {
380
359
const dom = new JSDOM ( html ) ;
381
360
let htmlDoc = dom . window . document . querySelector ( "body" ) ;
382
361
return fromRedactor ( htmlDoc , options ) ;
383
-
384
362
}
385
363
0 commit comments