Add custom matcher (https://github.com/woocommerce/woocommerce-blocks/pull/2780)
This commit is contained in:
parent
5247a77a43
commit
73adef6c85
|
@ -0,0 +1,4 @@
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import './to-render-block.js';
|
|
@ -0,0 +1,55 @@
|
|||
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: () =>
|
||||
`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,
|
||||
};
|
||||
},
|
||||
} );
|
|
@ -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',
|
||||
],
|
||||
|
|
|
@ -34,25 +34,6 @@ describe( `${ block.name } Block`, () => {
|
|||
} );
|
||||
|
||||
it( 'renders without crashing', async () => {
|
||||
// Gutenberg error
|
||||
expect(
|
||||
( await page.content() ).match(
|
||||
/Your site doesn’t 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 );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -31,25 +31,6 @@ describe( `${ block.name } Block`, () => {
|
|||
} );
|
||||
|
||||
it( 'renders without crashing', async () => {
|
||||
// Gutenberg error
|
||||
expect(
|
||||
( await page.content() ).match(
|
||||
/Your site doesn’t 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 );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -31,25 +31,6 @@ describe( `${ block.name } Block`, () => {
|
|||
} );
|
||||
|
||||
it( 'renders without crashing', async () => {
|
||||
// Gutenberg error
|
||||
expect(
|
||||
( await page.content() ).match(
|
||||
/Your site doesn’t 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 );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -22,26 +22,7 @@ describe( `${ block.name } Block`, () => {
|
|||
} );
|
||||
|
||||
it( 'renders without crashing', async () => {
|
||||
// Gutenberg error
|
||||
expect(
|
||||
( await page.content() ).match(
|
||||
/Your site doesn’t 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 () => {
|
||||
|
|
|
@ -36,25 +36,6 @@ describe( `${ block.name } Block`, () => {
|
|||
} );
|
||||
|
||||
it( 'renders without crashing', async () => {
|
||||
// Gutenberg error
|
||||
expect(
|
||||
( await page.content() ).match(
|
||||
/Your site doesn’t 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 );
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue