Skip to content

Commit

Permalink
Add tests from #35457
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 13, 2021
1 parent c87dae7 commit 76ca4f9
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/dom/src/dom/test/strip-html.js
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 );
} );
} );
} );

0 comments on commit 76ca4f9

Please sign in to comment.