Skip to content

Instantly share code, notes, and snippets.

@stevector
Last active August 8, 2019 02:48
Show Gist options
  • Save stevector/06eb6b6b555453f521b110ba1771accd to your computer and use it in GitHub Desktop.
Save stevector/06eb6b6b555453f521b110ba1771accd to your computer and use it in GitHub Desktop.
/**
* 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 );
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment