Skip to content

Commit

Permalink
Encode positive and negative behavioral expectaitons in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Mar 25, 2022
1 parent 1e27e2f commit bc1f535
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/blocks/src/api/test/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,48 @@ describe( 'block serializer', () => {

expect( content ).toBe( 'Bananas' );
} );
it( 'preserves content from invalid blocks when source information is present', () => {
registerBlockType( 'core/quote', {
category: 'text',
title: 'Quote',
attributes: { content: 'string' },
save: ( { attributes } ) =>
createElement( 'blockquote', {}, attributes.content ),
} );

const block = {
...createBlock( 'core/quote' ),
isValid: false,
__unstableBlockSource: {
blockName: 'quote',
attrs: {},
innerHTML: '<p>Not a quote</p>',
innerBlocks: [],
innerContent: ['<p>Not a quote</p>'],
},
};

expect( serializeBlock( block ) ).toBe(
'<!-- wp:quote -->\n<p>Not a quote</p>\n<!-- /wp:quote -->'
);
} );
it( 're-generates content from invalid blocks when source information is missing (losing content)', () => {
registerBlockType( 'core/quote', {
category: 'text',
title: 'Quote',
attributes: { content: 'string' },
save: ( { attributes } ) =>
createElement( 'blockquote', {}, attributes.content ),
} );

// missing attributes as a result of a failed parse
const block = {
...createBlock( 'core/quote' ),
isValid: false,
};

expect( serializeBlock( block ) ).toBe( '<!-- wp:quote /-->' );
} );
} );

describe( 'serialize()', () => {
Expand Down

0 comments on commit bc1f535

Please sign in to comment.