This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
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
1 parent
410797e
commit 579968b
Showing
1 changed file
with
83 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,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' ); | ||
} ); | ||
} ); |