2023-04-03 13:02:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
|
|
|
|
import { getBlocksBySlug } from '../../utils.js';
|
|
|
|
|
|
2020-06-25 13:00:27 +00:00
|
|
|
|
expect.extend( {
|
|
|
|
|
async toRenderBlock( page, block = {} ) {
|
|
|
|
|
const gutenbergNotFoundError = ( await page.content() ).match(
|
|
|
|
|
/Your site doesn’t include support for/gi
|
|
|
|
|
);
|
|
|
|
|
if ( gutenbergNotFoundError !== null ) {
|
|
|
|
|
return {
|
|
|
|
|
message: () =>
|
2020-09-07 17:31:10 +00:00
|
|
|
|
`the ${
|
|
|
|
|
block.name || 'block'
|
|
|
|
|
} is not registered and not loading in the editor.`,
|
2020-06-25 13:00:27 +00:00
|
|
|
|
pass: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gutenbergValidationError = ( await page.content() ).match(
|
|
|
|
|
/This block contains unexpected or invalid content/gi
|
|
|
|
|
);
|
|
|
|
|
if ( gutenbergValidationError !== null ) {
|
|
|
|
|
return {
|
|
|
|
|
message: () =>
|
2020-09-07 17:31:10 +00:00
|
|
|
|
`the ${
|
|
|
|
|
block.name || 'block'
|
|
|
|
|
} had a validation error while trying to render.`,
|
2020-06-25 13:00:27 +00:00
|
|
|
|
pass: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const errorBoundary = ( await page.content() ).match(
|
|
|
|
|
/There was an error whilst rendering/gi
|
|
|
|
|
);
|
|
|
|
|
if ( errorBoundary !== null ) {
|
|
|
|
|
return {
|
|
|
|
|
message: () =>
|
2020-09-07 17:31:10 +00:00
|
|
|
|
`the ${
|
|
|
|
|
block.name || 'block'
|
|
|
|
|
} had a js error that was caught by our errorBoundary.`,
|
2020-06-25 13:00:27 +00:00
|
|
|
|
pass: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 13:02:36 +00:00
|
|
|
|
const blocks = await getBlocksBySlug( block.slug );
|
|
|
|
|
if ( blocks >= 1 ) {
|
2020-06-25 13:00:27 +00:00
|
|
|
|
return {
|
|
|
|
|
message: () =>
|
2023-04-03 13:02:36 +00:00
|
|
|
|
`${ block.name || 'block' } with classname \`${
|
2020-06-25 13:00:27 +00:00
|
|
|
|
block.class
|
|
|
|
|
}\` did not render.`,
|
|
|
|
|
pass: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
message: () => `expected block to render without breaking.`,
|
|
|
|
|
pass: true,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
} );
|