-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recommendation how to snapshot custom blocks with jest #13364
Comments
Thanks for opening the issue. I think @Shelob9 had a tutorial somewhere about unit testing Gutenberg blocks. I think this is an area where the community should experiment and figure out the guidelines for the WordPress project. |
I did write a few on testing (Jest/Enzyme) for React with WordPress devs in mind:
Here is how we use Enzyme to test that our block shows up in the block inserter: https://github.com/CalderaWP/Caldera-Forms/blob/develop/cypress/integration/test.test.js#L46-L67 I am working on more specifically on blocks, but short version -- my opinion is how the block works is WordPress' concern. If the components you use to assemble the block are totally tested, you can assume |
Related WordPress/gutenberg-examples#26 |
I started encountering this issue today when I refactored a block from importing Anyways, there is a workaround. I pointed the (just showing the {
"moduleNameMapper": {
"simple-html-token": "<rootDir>/path/to/mock/simple-html-token"
}
} Then in the mock file ( module.exports = jest.fn(); |
I'm guessing the issue here is that the import is coming from a specific es6 directory from the
But I still don't get how/why this got triggered by switching from importing |
This discussion reminds me that we have this line added to Jest config: I don’t quite understand why it was added but it should be related. |
ooo ya that would be it! I'm guessing it was added for the same reason we're seeing this issue (to ignore that transform in tests). In other words if you remove it from the gb jest config the same error will probably pop up for gb. I just verified adding that line also fixes the issue. So likely the issue here is because Since this will also affect plugins that test with imported wp packages, should this ignore pattern be added to the |
I opened #15246 which tries to fix it for good with code :) |
I want to snapshot my custom blocks with jest. I found out how gutenberg is testing its components inside the block library, and I want to do it the same way.
So I have copied this helper to my project and set up a basic block.
However when I run
npm test
the following error is shown:When I run npm test the following error is shown
Block
Test
I included this package inside my package.json
Is there a recommended guide to snapshot custom gutenberg blocks?
I've read the testing guideline https://wordpress.org/gutenberg/handbook/contributors/testing-overview/, but it explains testing more in general then testing a specific gutenberg block with its components.
Thank you
The text was updated successfully, but these errors were encountered: