@@ -558,96 +558,99 @@ describe('Content', function () {
558558 } )
559559
560560 describe ( 'extractContent()' , function ( ) {
561- let host
562-
563- beforeEach ( function ( ) {
564- host = createElement ( '<div></div>' )
565- } )
566-
567561 it ( 'extracts the content' , function ( ) {
568- host . innerHTML = 'a'
569- const result = content . extractContent ( host )
562+ const element = createElement ( '<div>a</div>' )
563+ const result = content . extractContent ( element )
570564 // escape to show invisible characters
571565 expect ( escape ( result ) ) . toEqual ( 'a' )
572566 } )
573567
574568 it ( 'extracts the content from a document fragment' , function ( ) {
575- host . innerHTML = 'a<span>b</span>c'
576- const element = host
569+ const element = createElement ( '<div>a<span>b</span>c</div>' )
577570 const fragment = document . createDocumentFragment ( )
578- Array . from ( element . childNodes ) . forEach ( ( child ) => {
579- fragment . appendChild ( child . cloneNode ( true ) )
580- } )
571+ for ( const child of element . childNodes ) fragment . appendChild ( child . cloneNode ( true ) )
581572 expect ( content . extractContent ( fragment ) ) . toEqual ( 'a<span>b</span>c' )
582573 } )
583574
584575 it ( 'replaces a zeroWidthSpace with a <br> tag' , function ( ) {
585- host . innerHTML = 'a\u200B'
586- const result = content . extractContent ( host )
587- expect ( result ) . toEqual ( 'a<br>' )
576+ const element = createElement ( '<div>a\u200Bb</div>' )
577+ const result = content . extractContent ( element )
578+ expect ( result ) . toEqual ( 'a<br>b' )
579+ } )
580+
581+ it ( 'removes text nodes and line breaks at the end' , function ( ) {
582+ const element = createElement ( '<div>a\u200B</div>' )
583+ const result = content . extractContent ( element )
584+ expect ( result ) . toEqual ( 'a' )
585+
586+ const element2 = createElement ( '<div>b<br></div>' )
587+ const result2 = content . extractContent ( element2 )
588+ expect ( result2 ) . toEqual ( 'b' )
588589 } )
589590
590591 it ( 'removes zeroWidthNonBreakingSpaces' , function ( ) {
591- host . innerHTML = 'a\uFEFF'
592- const result = content . extractContent ( host )
592+ const element = createElement ( '<div>a\uFEFFb</div>' )
593+ const result = content . extractContent ( element )
593594 // escape to show invisible characters
594- expect ( escape ( result ) ) . toEqual ( 'a ' )
595+ expect ( escape ( result ) ) . toEqual ( 'ab ' )
595596 } )
596597
597598 it ( 'removes a marked linebreak' , function ( ) {
598- host . innerHTML = '< br data-editable="remove">'
599- const result = content . extractContent ( host )
600- expect ( result ) . toEqual ( '' )
599+ const element = createElement ( '<div>Foo < br data-editable="remove">Bar</div>' )
600+ const result = content . extractContent ( element )
601+ expect ( result ) . toEqual ( 'Foo Bar ' )
601602 } )
602603
603604 it ( 'removes two nested marked spans' , function ( ) {
604- host . innerHTML = '< span data-editable="unwrap"><span data-editable="unwrap">a</span></span>'
605- const result = content . extractContent ( host )
605+ const element = createElement ( '<div>< span data-editable="unwrap"><span data-editable="unwrap">a</span></span></div>' )
606+ const result = content . extractContent ( element )
606607 expect ( result ) . toEqual ( 'a' )
607608 } )
608609
609610 it ( 'removes two adjacent marked spans' , function ( ) {
610- host . innerHTML = '< span data-editable="remove"></span><span data-editable="remove"></span>'
611- const result = content . extractContent ( host )
611+ const element = createElement ( '<div>< span data-editable="remove"></span><span data-editable="remove"></span></div>' )
612+ const result = content . extractContent ( element )
612613 expect ( result ) . toEqual ( '' )
613614 } )
614615
615616 it ( 'unwraps two marked spans around text' , function ( ) {
616- host . innerHTML = ' |<span data-editable="unwrap">a</span>|<span data-editable="unwrap">b</span>|'
617- const result = content . extractContent ( host )
617+ const element = createElement ( '<div> |<span data-editable="unwrap">a</span>|<span data-editable="unwrap">b</span>|</div>' )
618+ const result = content . extractContent ( element )
618619 expect ( result ) . toEqual ( '|a|b|' )
619620 } )
620621
621622 it ( 'unwraps a "ui-unwrap" span' , function ( ) {
622- host . innerHTML = ' a<span data-editable="ui-unwrap">b</span>c'
623- const result = content . extractContent ( host )
623+ const element = createElement ( '<div> a<span data-editable="ui-unwrap">b</span>c</div>' )
624+ const result = content . extractContent ( element )
624625 expect ( result ) . toEqual ( 'abc' )
625626 } )
626627
627628 it ( 'removes a "ui-remove" span' , function ( ) {
628- host . innerHTML = ' a<span data-editable="ui-remove">b</span>c'
629- const result = content . extractContent ( host )
629+ const element = createElement ( '<div> a<span data-editable="ui-remove">b</span>c</div>' )
630+ const result = content . extractContent ( element )
630631 expect ( result ) . toEqual ( 'ac' )
631632 } )
632633
633634 describe ( 'called with keepUiElements' , function ( ) {
634635
635636 it ( 'does not unwrap a "ui-unwrap" span' , function ( ) {
636- host . innerHTML = ' a<span data-editable="ui-unwrap">b</span>c'
637- const result = content . extractContent ( host , true )
637+ const element = createElement ( '<div> a<span data-editable="ui-unwrap">b</span>c</div>' )
638+ const result = content . extractContent ( element , true )
638639 expect ( result ) . toEqual ( 'a<span data-editable="ui-unwrap">b</span>c' )
639640 } )
640641
641642 it ( 'does not remove a "ui-remove" span' , function ( ) {
642- host . innerHTML = ' a<span data-editable="ui-remove">b</span>c'
643- const result = content . extractContent ( host , true )
643+ const element = createElement ( '<div> a<span data-editable="ui-remove">b</span>c</div>' )
644+ const result = content . extractContent ( element , true )
644645 expect ( result ) . toEqual ( 'a<span data-editable="ui-remove">b</span>c' )
645646 } )
646647 } )
647648
648649 describe ( 'with ranges' , function ( ) {
650+ let host
649651
650652 beforeEach ( function ( ) {
653+ host = createElement ( '<div></div>' )
651654 document . body . appendChild ( host )
652655 this . range = rangy . createRange ( )
653656 } )
0 commit comments