Skip to content

Commit

Permalink
Fix block validation error message (#13499)
Browse files Browse the repository at this point in the history
* Rename variable to make code more clear

* Fix display of expected and actual block HTML

The variable were in the wrong order, making the message confusing. It
would show the actual HTML as the expected HTML and visa versa.

* Change wording to be more clear

Expected & Actual were confusing words to use in this content. This
change makes the message actually reflect what the values are.

* Regenerate docs
  • Loading branch information
atimmer authored and youknowriad committed Mar 20, 2019
1 parent af4288e commit e6f637f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ Logs to console in development environments when invalid.

- **blockTypeOrName** `(string|Object)`: Block type.
- **attributes** `Object`: Parsed block attributes.
- **innerHTML** `string`: Original block content.
- **originalBlockContent** `string`: Original block content.

**Returns**

Expand Down
20 changes: 10 additions & 10 deletions packages/blocks/src/api/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,30 +620,30 @@ export function isEquivalentHTML( actual, expected ) {
*
* Logs to console in development environments when invalid.
*
* @param {string|Object} blockTypeOrName Block type.
* @param {Object} attributes Parsed block attributes.
* @param {string} innerHTML Original block content.
* @param {string|Object} blockTypeOrName Block type.
* @param {Object} attributes Parsed block attributes.
* @param {string} originalBlockContent Original block content.
*
* @return {boolean} Whether block is valid.
*/
export function isValidBlockContent( blockTypeOrName, attributes, innerHTML ) {
export function isValidBlockContent( blockTypeOrName, attributes, originalBlockContent ) {
const blockType = normalizeBlockType( blockTypeOrName );
let saveContent;
let generatedBlockContent;
try {
saveContent = getSaveContent( blockType, attributes );
generatedBlockContent = getSaveContent( blockType, attributes );
} catch ( error ) {
log.error( 'Block validation failed because an error occurred while generating block content:\n\n%s', error.toString() );
return false;
}

const isValid = isEquivalentHTML( innerHTML, saveContent );
const isValid = isEquivalentHTML( originalBlockContent, generatedBlockContent );
if ( ! isValid ) {
log.error(
'Block validation failed for `%s` (%o).\n\nExpected:\n\n%s\n\nActual:\n\n%s',
'Block validation failed for `%s` (%o).\n\nContent generated by `save` function:\n\n%s\n\nContent retrieved from post body:\n\n%s',
blockType.name,
blockType,
saveContent,
innerHTML
generatedBlockContent,
originalBlockContent
);
}

Expand Down

0 comments on commit e6f637f

Please sign in to comment.