-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (50 loc) · 1.64 KB
/
index.js
File metadata and controls
58 lines (50 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* External dependencies
*/
import { expect } from 'chai';
/**
* Internal dependencies
*/
import { createElement, renderToString, concatChildren } from '../';
describe( 'element', () => {
describe( 'renderToString', () => {
it( 'should return an empty string for a falsey value', () => {
expect( renderToString() ).to.equal( '' );
expect( renderToString( false ) ).to.equal( '' );
expect( renderToString( null ) ).to.equal( '' );
expect( renderToString( 0 ) ).to.equal( '' );
} );
it( 'should return a string verbatim', () => {
expect( renderToString( 'Zucchini' ) ).to.equal( 'Zucchini' );
} );
it( 'should return a string from an array', () => {
expect( renderToString( [
'Zucchini ',
createElement( 'em', null, 'is a' ),
' summer squash'
] ) ).to.equal( 'Zucchini <em>is a</em> summer squash' );
} );
it( 'should return a string from an element', () => {
expect( renderToString(
createElement( 'strong', null, 'Courgette' )
) ).to.equal( '<strong>Courgette</strong>' );
} );
} );
describe( 'concatChildren', () => {
it( 'should return an empty array for undefined children', () => {
expect( concatChildren() ).to.eql( [] );
} );
it( 'should concat the string arrays', () => {
expect( concatChildren( [ 'a' ], 'b' ) ).to.eql( [ 'a', 'b' ] );
} );
it( 'should concat the object arrays and rewrite keys', () => {
const concat = concatChildren(
[ createElement( 'strong', null, 'Courgette' ) ],
createElement( 'strong', null, 'Concombre' )
);
expect( concat.length ).to.equal( 2 );
expect( concat[ 0 ].key = 0 );
expect( concat[ 1 ].key = 1 );
} );
} );
} );