-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import stripHTML from '../strip-html'; | ||
|
||
describe( 'stripHTML', () => { | ||
it( 'should strip valid HTML', () => { | ||
const input = | ||
'<strong>Here is some text</strong> that contains <em>HTML markup</em>.'; | ||
const output = 'Here is some text that contains HTML markup.'; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
|
||
it( 'should strip invalid HTML', () => { | ||
const input = | ||
'<strong>Here is some text</em> <p></div>that contains HTML markup</p>.'; | ||
const output = 'Here is some text that contains HTML markup.'; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
|
||
describe( 'whitespace preservation', () => { | ||
it( 'should preserve leading spaces', () => { | ||
const input = | ||
' <strong>Here is some text</strong> with <em>leading spaces</em>.'; | ||
const output = ' Here is some text with leading spaces.'; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
|
||
it( 'should preserve leading spaces with HTML', () => { | ||
const input = | ||
'<strong> Here is some text</strong> with <em>leading spaces</em>.'; | ||
const output = ' Here is some text with leading spaces.'; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
|
||
it( 'should preserve trailing spaces with HTML', () => { | ||
const input = | ||
'<strong>Here is some text</strong> with <em>trailing spaces</em>. '; | ||
const output = 'Here is some text with trailing spaces. '; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
|
||
it( 'should preserve consequtive spaces within string', () => { | ||
const input = | ||
'<strong>Here is some text</strong> with <em>a lot of spaces inside</em>.'; | ||
const output = | ||
'Here is some text with a lot of spaces inside.'; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
|
||
it( 'should preserve new lines in multi-line HTML string', () => { | ||
const input = `<div> | ||
Here is some | ||
<em>text</em> | ||
with new lines | ||
</div>`; | ||
|
||
const output = ` | ||
Here is some | ||
text | ||
with new lines | ||
`; | ||
expect( stripHTML( input ) ).toBe( output ); | ||
} ); | ||
} ); | ||
} ); |