-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathis-valid-block.spec.js
59 lines (52 loc) · 1.4 KB
/
is-valid-block.spec.js
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
59
/**
* WordPress dependencies
*/
import { isValidBlockContent } from '@wordpress/blocks';
import { createElement } from '@wordpress/element';
describe( 'isValidBlockContent', () => {
beforeAll( () => {
// Load all hooks that modify blocks
require( '../../packages/editor/src/hooks' );
} );
it( 'should use the namespace in the classname for non-core blocks', () => {
const valid = isValidBlockContent(
{
save: ( { attributes } ) => createElement( 'div', null, attributes.fruit ),
name: 'myplugin/fruit',
},
{ fruit: 'Bananas' },
'<div class="wp-block-myplugin-fruit">Bananas</div>'
);
expect( valid ).toBe( true );
} );
it( 'should include additional classes in block attributes', () => {
const valid = isValidBlockContent(
{
save: ( { attributes } ) => createElement( 'div', {
className: 'fruit',
}, attributes.fruit ),
name: 'myplugin/fruit',
},
{
fruit: 'Bananas',
className: 'fresh',
},
'<div class="wp-block-myplugin-fruit fruit fresh">Bananas</div>'
);
expect( valid ).toBe( true );
} );
it( 'should not add a className if falsy', () => {
const valid = isValidBlockContent(
{
save: ( { attributes } ) => createElement( 'div', null, attributes.fruit ),
name: 'myplugin/fruit',
supports: {
className: false,
},
},
{ fruit: 'Bananas' },
'<div>Bananas</div>'
);
expect( valid ).toBe( true );
} );
} );