|
4 | 4 | * WordPress dependencies
|
5 | 5 | */
|
6 | 6 | import { addFilter, removeAllFilters, removeFilter } from '@wordpress/hooks';
|
| 7 | +import { logged } from '@wordpress/deprecated'; |
7 | 8 | import { select } from '@wordpress/data';
|
8 | 9 |
|
9 | 10 | /**
|
@@ -61,6 +62,11 @@ describe( 'blocks', () => {
|
61 | 62 | setUnregisteredTypeHandlerName( undefined );
|
62 | 63 | setDefaultBlockName( undefined );
|
63 | 64 | unstable__bootstrapServerSideBlockDefinitions( {} );
|
| 65 | + |
| 66 | + // Reset deprecation logging to ensure we properly track warnings. |
| 67 | + for ( const key in logged ) { |
| 68 | + delete logged[ key ]; |
| 69 | + } |
64 | 70 | } );
|
65 | 71 |
|
66 | 72 | describe( 'registerBlockType()', () => {
|
@@ -832,6 +838,41 @@ describe( 'blocks', () => {
|
832 | 838 | // Only attributes of block1 are supposed to be edited by the filter thus it must differ from block2.
|
833 | 839 | expect( block1.attributes ).not.toEqual( block2.attributes );
|
834 | 840 | } );
|
| 841 | + |
| 842 | + it( 'should allow non-string descriptions at registration but warn for undesired usage.', () => { |
| 843 | + const newDescription = <p>foo bar</p>; |
| 844 | + |
| 845 | + const block = registerBlockType( 'my-plugin/test-block-1', { |
| 846 | + ...defaultBlockSettings, |
| 847 | + description: newDescription, |
| 848 | + } ); |
| 849 | + |
| 850 | + expect( block.description ).toBe( newDescription ); |
| 851 | + expect( console ).toHaveWarnedWith( |
| 852 | + 'Declaring non-string block descriptions is deprecated since version 6.2.' |
| 853 | + ); |
| 854 | + } ); |
| 855 | + |
| 856 | + it( 'should allow non-string descriptions through `blocks.registerBlockType` filter but warn for undesired usage.', () => { |
| 857 | + const newDescription = <p>foo bar</p>; |
| 858 | + addFilter( |
| 859 | + 'blocks.registerBlockType', |
| 860 | + 'core/blocks/non-string-description', |
| 861 | + ( settings ) => { |
| 862 | + settings.description = newDescription; |
| 863 | + return settings; |
| 864 | + } |
| 865 | + ); |
| 866 | + const block = registerBlockType( |
| 867 | + 'my-plugin/test-block-2', |
| 868 | + defaultBlockSettings |
| 869 | + ); |
| 870 | + |
| 871 | + expect( block.description ).toBe( newDescription ); |
| 872 | + expect( console ).toHaveWarnedWith( |
| 873 | + 'Declaring non-string block descriptions is deprecated since version 6.2.' |
| 874 | + ); |
| 875 | + } ); |
835 | 876 | } );
|
836 | 877 |
|
837 | 878 | test( 'registers block from metadata', () => {
|
|
0 commit comments