community-content
community-content copied to clipboard
[SUBMIT] How to write Jest tests for Strapi Plugins
Introduction
If you a writing a plugin that lots of other people and companies or if other people are going to contribute to it tests are a must. We just had a security issue which could of been caught by unit tests. However, there are not guides on how to write tests for a custom Strapi plugin.
Outline
- What is Jest
- Add Jest to your plugin
- Mocking the Strapi Object
- Mocking
ctx
- Testing Controllers
- Testing Services
- Running Tests
- Automatically Run Tests with Github Actions
- Conclusion
My content is
- [x] A Strapi Tutorial / Guide / How to article
- [ ] About Headless, CMS, javascript, open source, or jamstack
- [ ] Other, specify
I can write this article :) However I am curious as to what the payment structure/requirements are.
Just finished up writing tests for my plugin hence why I want to write an article :) https://github.com/excl-networks/strapi-plugin-ezforms/tree/master/tests
@Cpaczek great topic. You can start on it. Just confirm when you get started. Thank you. 🙂
Hello @Cpaczek 👋 Could you confirm if you are writing this article?
Hello @Cpaczek 👋 Could you confirm if you are writing this article?
Yes I plan on writing this, I don't have a firm timeline right now.
Hello @Cpaczek! How is this topic doing? Let us know otherwise we will close this issue since it has taken a long time now.
Hello @Cpaczek! How is this topic doing? Let us know otherwise we will close this issue since it has taken a long time now.
Hi, sorry been super busy, I don't have a set time to work on this so if someone else wants to take it over they can.
@dessireugarte Here is the first draft, please let me know your thoughts: https://gist.github.com/Cpaczek/4c9d559cbfe13ffad5bc334ce4477ac6
I wrote it in markdown as I could not figure out how to duplicate the dropbox thing.
Hello @Cpaczek 👋 Thanks for submitting the draft. We will review it, and if we have any comments or suggestions, we will let you know. Otherwise, we will publish it between the first and second week of January.
Hello @Cpaczek 👋 Could you please register on the Write for the Community page form?
@Cpaczek I like your article, when reviewing it, I realized some people would like to follow along. But you only provided a completed example. I forked your repo and removed the jest, test and test.yaml file. This way folks can have a fresh start and follow along with your tutorial. I think it would be helpful to include it. Let me know what you think. Otherwise your article is all set to go.
@Cpaczek I like your article, when reviewing it, I realized some people would like to follow along. But you only provided a completed example. I forked your repo and removed the jest, test and test.yaml file. This way folks can have a fresh start and follow along with your tutorial. I think it would be helpful to include it. Let me know what you think. Otherwise your article is all set to go.
Ya, that's probably a good idea, the reason why I didn't include it is I assumed people already had a plugin they wanted to add tests to. Do you want to make a PR to a new branch and just have 2 branches on the same repo or just have them in 2 different repos? Either way works for me.
You can just share the link https://github.com/PaulBratslavsky/strapi-jest-tutorial just to keep it simple. Thank you.
You can just share the link https://github.com/PaulBratslavsky/strapi-jest-tutorial just to keep it simple. Thank you.
Okay I added it to the Gist
@Cpaczek this has been reviewed and scheduled for publishing will let you know when it goes live.
Hello @Cpaczek! Thanks for submitting your invoice.
You should register yourself once as an "Individual Vendor" in this form, please let me know if you have any questions about the form. Just be aware that in the W-8BEN form:
- 5 is not mandatory
- 6a & 6b are only necessary if you have a tax number in your own country.
If you already did that step, then I would only be missing your proof of bank details (bank statement, bank letter, online screenshot). You can send the bank account details to my email address [email protected]
Please feel free to reach out to me if you have any questions!
Hello @Cpaczek! Could you please confirm for us when you receive your payment?
Hello @Cpaczek! Could you please confirm for us when you receive your payment?
Yes thank you