Add tests for textContent().

This commit is contained in:
Jeff Stieler 2018-12-18 11:03:11 -07:00
parent 1935e75f5c
commit f2df49ce24
1 changed files with 83 additions and 0 deletions

View File

@ -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' );
} );
} );