-
Notifications
You must be signed in to change notification settings - Fork 54
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
[🛠️] Add unit tests (jest) #11
Comments
Hey @TheDanniCraft, I have a question: Should the tests run before the user raises the PR, or should they run on GitHub itself? Thanks! |
Hey @Muhammad-Owais-Warsi, 👋 The tests should ideally serve two purposes:
Let me know if you have any questions or need guidance. I’m here to help! Looking forward to your contributions. 🚀 |
Thanks a lot @TheDanniCraft . Actually I don't even know ehre to start from, I have gone through the |
No worries, I’m not super familiar with jest either, but I think what we’ll need to do is mock the API responses to handle the dynamic data. This way, we can simulate how the functions behave without actually hitting the real API (Jest Mock Functions). Feel free to give it a try, and let me know if you run into any issues—I’ll try my best to help out! 😊 |
hey @TheDanniCraft |
hey @TheDanniCraft |
Hey @adeson33, Thank you so much for your interest in helping out, I really appreciate it! ❤️ Regarding your issue with the activity-log: could you please create a separate issue for that? This will help us keep discussions focused and address your concern about the repeated logs more effectively. As for the testing setup, the main goals are:
I agree that having a clear list of test function points would make the process more efficient. However, I’ll admit I don’t have much experience with test coverage strategies, so I’m not sure what functions would make the most sense to test. If you or anyone else has suggestions for a good testing strategy, I’d love to hear them! Let me know if you’d like to take on any part of this process or if you have ideas for how we should proceed—I’m happy to collaborate. 😊 |
@TheDanniCraft |
That's great. I think the main functions are in the |
@adeson33 @Muhammad-Owais-Warsi Thanks for giving it a try! ❤️ I found this article on dev.to, maybe it’ll help you in writing the unit tests. Also, I think it might be a good idea if you make a checklist of the tests you’re working on. This way, we avoid duplicate efforts and ensure everything is covered without overlap. Once a task is completed, mark it off to keep track of the progress efficiently. |
I was going through the codebase and jest documentation only and I think I can give try to the functions in |
hey @Muhammad-Owais-Warsi , nice to work with you |
@adeson33 you can find the |
Hey, @TheDanniCraft @adeson33 , I've tried of writing a test for this function in the Once verified we can create a folder and start writing them in the actual codebase. Thanks:) https://github.com/TheDanniCraft/activity-log/blob/master/src/utils/github.js#L10 |
Thanks for sharing your test! You’re definitely on the right track, but I noticed a few issues (Copilot helped to catch some of them) that might need addressing to make the test work properly:
Here’s a Copilot-generated version of the test that incorporates these improvements (feel free to tweak as needed). @adeson33, maybe you can review this to verify if these tests are good:
Lastly, you might want to consider opening a draft PR for your work. This way, everyone can collaborate directly on your progress and share feedback. |
Thanks a lot for pointing out the corrections. I'll make the corrections and will let you know.
Thanks. |
The goal here is to mock the API responses instead of calling the real API. By mocking, we ensure that the input data is always the same, making the tests predictable and replicable. This way, we avoid issues with fluctuating API data or network problems, and we have full control over the responses we want to test. For example, in the test, we mock the response like this: octokit.rest.activity.listReposStarredByAuthenticatedUser
.mockResolvedValueOnce({ data: [{ owner: { login: 'user1' }, name: 'repo1' }] })
.mockResolvedValueOnce({ data: [] }); // End of pagination This ensures that the test always uses the same data and can be reliably run every time, no matter what happens in the actual API. Let me know if you need further clarification! 😊 |
Thanks for the clarification,but I think you misunderstood my question. |
Is your feature request related to a problem? Please describe.
Currently, we don’t have automated tests set up, which makes it harder to ensure the code quality and reliability of new features or bug fixes introduced through Pull Requests (PRs). Manually testing each PR can be time-consuming and error-prone.
Describe the solution you'd like
I propose adding Jest as a testing framework to the project. This will allow us to write unit tests that automatically run each time a new PR is opened. These tests will ensure that the code works as expected and reduces the risk of introducing bugs in the codebase. The tests should run via a continuous integration pipeline (like GitHub Actions) to ensure every PR is tested before being merged.
Describe alternatives you've considered
-
Additional context
-
The text was updated successfully, but these errors were encountered: