woocommerce/plugins/woocommerce-blocks/tests/e2e-jest/config/custom-matchers/to-render-block.js

64 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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