This commit is contained in:
Seghir Nadir 2020-06-25 14:00:27 +01:00 committed by GitHub
parent 5247a77a43
commit 73adef6c85
8 changed files with 65 additions and 100 deletions

View File

@ -0,0 +1,4 @@
/**
* Internal dependencies
*/
import './to-render-block.js';

View File

@ -0,0 +1,55 @@
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 blockElement = await page.$( block.class );
if ( blockElement === null ) {
return {
message: () =>
`the ${ block.name || 'block' } with classname \`${
block.class
}\` did not render.`,
pass: false,
};
}
return {
message: () => `expected block to render without breaking.`,
pass: true,
};
},
} );

View File

@ -21,6 +21,7 @@ module.exports = {
// A list of paths to modules that run some code to configure or set up the testing framework
// before each test
setupFilesAfterEnv: [
'<rootDir>/tests/e2e-tests/config/custom-matchers/index.js',
'<rootDir>/tests/e2e-tests/config/jest.setup.js',
'expect-puppeteer',
],

View File

@ -34,25 +34,6 @@ describe( `${ block.name } Block`, () => {
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
await expect( page ).toRenderBlock( block );
} );
} );

View File

@ -31,25 +31,6 @@ describe( `${ block.name } Block`, () => {
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
await expect( page ).toRenderBlock( block );
} );
} );

View File

@ -31,25 +31,6 @@ describe( `${ block.name } Block`, () => {
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
await expect( page ).toRenderBlock( block );
} );
} );

View File

@ -22,26 +22,7 @@ describe( `${ block.name } Block`, () => {
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
await expect( page ).toRenderBlock( block );
} );
it( 'can toggle field label', async () => {

View File

@ -36,25 +36,6 @@ describe( `${ block.name } Block`, () => {
} );
it( 'renders without crashing', async () => {
// Gutenberg error
expect(
( await page.content() ).match(
/Your site doesnt include support for/gi
)
).toBeNull();
// Our ErrorBoundary
expect(
( await page.content() ).match(
/There was an error whilst rendering/gi
)
).toBeNull();
// Validation Error
expect(
( await page.content() ).match(
/This block contains unexpected or invalid content/gi
)
).toBeNull();
await expect( page ).toMatchElement( block.class );
await expect( page ).toRenderBlock( block );
} );
} );