Last active
August 8, 2019 02:48
-
-
Save stevector/06eb6b6b555453f521b110ba1771accd to your computer and use it in GitHub Desktop.
Copy of https://github.com/WordPress/gutenberg/blob/master/test/integration/is-valid-block.spec.js
This file contains hidden or 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
/** | |
* 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