Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Add tests for textContent().
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffstieler committed Dec 18, 2018
1 parent 410797e commit 579968b
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions packages/components/src/filters/advanced/test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Internal dependencies
*/
import { textContent } from '../utils';

describe( 'textContent()', () => {
test( 'should be got text `Hello World`', () => {
const component = (
<div>
<h1>Hello</h1> World
</div>
);

expect( textContent( component ) ).toBe( 'Hello World' );
} );

test( 'render variable', () => {
const component = (
<div>
<h1>Hello</h1> { 'World' + '2' }
</div>
);

expect( textContent( component ) ).toBe( 'Hello World2' );
} );

test( 'render variable2', () => {
const component = (
<div>
<h1>Hello</h1> { 1 + 1 }
</div>
);

expect( textContent( component ) ).toBe( 'Hello 2' );
} );

test( 'should output empty string', () => {
const component = ( <div /> );

expect( textContent( component ) ).toBe( '' );
} );

test( 'array children', () => {
const component = (
<div>
<h1>Hello</h1> World
{
[ 'a', <h2 key="b">b</h2> ]
}
</div>
);

expect( textContent( component ) ).toBe( 'Hello Worldab' );
} );

test( 'array children with null', () => {
const component = (
<div>
<h1>Hello</h1> World
{
[ 'a', null ]
}
</div>
);

expect( textContent( component ) ).toBe( 'Hello Worlda' );
} );

test( 'array component', () => {
const component = ( [
<h1>a</h1>,
'b',
'c',
(
<div>
<h2>x</h2>y
</div>
),
] );

expect( textContent( component ) ).toBe( 'abcxy' );
} );
} );

0 comments on commit 579968b

Please sign in to comment.