@@ -33,6 +33,20 @@ function setupHighlightEnv (context, text) {
3333 )
3434 }
3535
36+ // we don't want to compare the native range in our tests since this is a native JS object
37+ context . extractWithoutNativeRange = function ( type ) {
38+ const positions = context . editable . getHighlightPositions ( { editableHost : context . div , type} )
39+ if ( ! positions ) return undefined
40+ const extracted = { }
41+ for ( const id in positions ) {
42+ const val = positions [ id ]
43+ // eslint-disable-next-line
44+ const { nativeRange, ...withoutNativeRange } = val
45+ extracted [ id ] = withoutNativeRange
46+ }
47+ return extracted
48+ }
49+
3650 context . extract = function ( type ) {
3751 return context . editable . getHighlightPositions ( { editableHost : context . div , type} )
3852 }
@@ -155,10 +169,16 @@ describe('Highlighting', function () {
155169Make The <br> World Go Round` )
156170
157171 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
158- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
172+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
159173 expect ( startIndex ) . to . equal ( 3 )
160174 } )
161175
176+ it ( 'has the native range' , function ( ) {
177+ this . highlightRange ( 'myId' , 3 , 7 )
178+ const extracted = this . extract ( )
179+ expect ( extracted . myId . nativeRange . constructor . name ) . to . equal ( 'Range' )
180+ } )
181+
162182 it ( 'can handle adjaccent highlights' , function ( ) {
163183 this . highlightRange ( 'first' , 0 , 1 )
164184 this . highlightRange ( 'second' , 1 , 2 )
@@ -194,7 +214,7 @@ Make The <br> World Go Round`)
194214le Make The <br> World Go Round` )
195215
196216 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
197- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
217+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
198218
199219 } )
200220
@@ -232,7 +252,7 @@ le Make The <br> World Go Round`)
232252</span>
233253 Make The <br> World Go Round` )
234254 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
235- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
255+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
236256 } )
237257
238258 it ( 'can handle intersecting highlights' , function ( ) {
@@ -261,7 +281,7 @@ le Make The <br> World Go Round`)
261281<span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment">o</span>p
262282<span class="highlight-comment" data-word-id="third" data-editable="ui-unwrap" data-highlight="comment">le</span> </span>Make The <br> World Go Round` )
263283 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
264- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
284+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
265285 } )
266286
267287 it ( 'can handle highlights containing break tags' , function ( ) {
@@ -277,7 +297,7 @@ le Make The <br> World Go Round`)
277297<span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment"> The <br> World</span>
278298 Go Round` )
279299
280- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
300+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
281301 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
282302
283303 } )
@@ -305,7 +325,7 @@ le Make The <br> World Go Round`)
305325
306326
307327 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
308- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
328+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
309329
310330 } )
311331
@@ -323,7 +343,7 @@ le Make The <br> World Go Round`)
323343<span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment">a</span>
324344ke The <br> World Go Round` )
325345
326- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
346+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
327347 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
328348 } )
329349
@@ -380,7 +400,7 @@ e Mak</span>e The<span class="highlight-comment" data-word-id="sixth" data-edita
380400o Round</span>` )
381401
382402 const extractedHtml = this . getHtml ( )
383- const extractedRanges = this . extract ( )
403+ const extractedRanges = this . extractWithoutNativeRange ( )
384404
385405 expect ( extractedRanges ) . to . deep . equal ( expectedRanges )
386406 expect ( extractedHtml ) . to . equal ( expectedHtml )
@@ -398,7 +418,7 @@ o Round</span>`)
398418 )
399419 } )
400420
401- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
421+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
402422 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
403423 } )
404424
@@ -448,7 +468,7 @@ o Round</span>`)
448468<span class="highlight-comment" data-word-id="myId" data-editable="ui-unwrap" data-highlight="comment">ple </span>
449469Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" data-editable="ui-unwrap" data-highlight="spellcheck">orld</span> Go Round` )
450470 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
451- expect ( this . extract ( 'comment' ) ) . to . deep . equal ( expectedRanges )
471+ expect ( this . extractWithoutNativeRange ( 'comment' ) ) . to . deep . equal ( expectedRanges )
452472 expect ( startIndex ) . to . equal ( 3 )
453473 } )
454474
@@ -486,9 +506,9 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
486506 const { start, end} = range . toCharacterRange ( this . div )
487507 this . highlightRange ( 'char' , start , end )
488508 if ( expectedLength === 0 ) {
489- expect ( this . extract ( ) ) . to . equal ( undefined )
509+ expect ( this . extractWithoutNativeRange ( ) ) . to . equal ( undefined )
490510 } else {
491- expect ( this . extract ( ) ) . to . deep . equal ( {
511+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( {
492512 char : {
493513 start : 0 ,
494514 end : expectedLength ,
@@ -505,7 +525,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
505525 it ( 'can handle highlights surrounding <span> tags' , function ( ) {
506526 setupHighlightEnv ( this , 'a<span>b</span>cd' )
507527 this . highlightRange ( 'first' , 1 , 3 )
508- const extract = this . extract ( )
528+ const extract = this . extractWithoutNativeRange ( )
509529
510530 expect ( extract . first . text ) . to . equal ( 'bc' )
511531
@@ -516,7 +536,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
516536 it ( 'can handle highlights intersecting <span> tags' , function ( ) {
517537 setupHighlightEnv ( this , 'a<span data-word-id="x">bc</span>d' )
518538 this . highlightRange ( 'first' , 0 , 2 )
519- const extract = this . extract ( )
539+ const extract = this . extractWithoutNativeRange ( )
520540
521541 expect ( extract . first . text ) . to . equal ( 'ab' )
522542
@@ -552,7 +572,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
552572
553573 const expectedHtml = '<span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment">π</span> Make The \n π Go \nπ'
554574
555- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
575+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
556576 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
557577 } )
558578
@@ -567,7 +587,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
567587 }
568588 const expectedHtml = 'π<span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment"> Make T</span>he \n π Go \nπ'
569589 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
570- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
590+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
571591
572592
573593 } )
@@ -584,7 +604,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
584604
585605 const expectedHtml = 'π Make <span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment">The \n π </span>Go \nπ'
586606 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
587- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
607+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
588608
589609 } )
590610
@@ -599,7 +619,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
599619 }
600620 const expectedHtml = 'π Make The \n π <span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment">Go \nπ</span>'
601621 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
602- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
622+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
603623 } )
604624
605625 it ( 'extracts a readable text' , function ( ) {
@@ -613,7 +633,7 @@ Make The <br> W<span class="highlight-spellcheck" data-word-id="spellcheckId" da
613633 }
614634 const expectedHtml = '<span class="highlight-comment" data-word-id="first" data-editable="ui-unwrap" data-highlight="comment">π Make The \n π Go \nπ</span>'
615635 expect ( this . getHtml ( ) ) . to . equal ( expectedHtml )
616- expect ( this . extract ( ) ) . to . deep . equal ( expectedRanges )
636+ expect ( this . extractWithoutNativeRange ( ) ) . to . deep . equal ( expectedRanges )
617637 } )
618638
619639 it ( 'notify change on add highlight when dispatcher is given' , function ( ) {
0 commit comments