Skip to content
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

Tests: Improve the Code Coverage initiative using Jest #480

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

timothymarois
Copy link
Collaborator

  • Implements npm run test using Jest, ts-jest, jest-environment-jsdom
  • Implements first modal tests

@timothymarois timothymarois changed the title Jest tests – Improve the Code Coverage initiative Tests: Improve the Code Coverage initiative using Jest Mar 11, 2023
@zoltanszogyenyi
Copy link
Member

zoltanszogyenyi commented Mar 11, 2023

Hey @timothymarois,

This is a much needed update for the Flowbite Library to make it sustainable in the future.

I'll be here to assist whenever needed - took a look at the code, it looks good to me!

I suppose these tests will later be integrated with CI as well when creating PRs.

Cheers,
Zoltan

PS: let me know when the basis of this update has been made since I could muster the community from Flowbite to help us out with some unit tests, though we'll need to write a contribution guide for these tests so we make sure everyone is onboard with the same approach.

@CorwinDev
Copy link
Contributor

Hi @timothymarois,

I would love to help to this pull request, do you have anything i can pickup?

@timothymarois
Copy link
Collaborator Author

@zoltanszogyenyi Yep, that's the idea; if we can get enough coverage, then we can integrate CI/Actions and have automated tests run on every PR submitted.

@CorwinDev Right now, I just set up the basics, but if you want to start testing the more complex items such as data attributes, etc. We can mimic the modal test I provided for the other components.

@zoltanszogyenyi
Copy link
Member

zoltanszogyenyi commented Mar 11, 2023

Hey @timothymarois @CorwinDev,

I think it's best if we take each component step by step and start with the easier stuff.

And we should create a "checkbox" tasks template for each component unit test, for example:

  • Created a new test file for the component
  • Created the constructor tests
  • Created a test for each public method (ie. show, hide, toggle)

For reference the Flowbite React has some pretty good tests going on and we could use that as inspiration:

Stuff like should be closed by Esc key press. and should be closed by clicking outside if the "dismissible" prop is passed. are pretty neat, but I think that in our case we do need some special stuff for the data attributes, to check if the correct classes are added when a specific action is performed, and also check for the aria-role attributes.

So my suggestion is to finish up the Modal component as a benchmark and then go onto the other components.

We can also take some inspiration from Bootstrap's unit tests as they also use data attributes and are battle tested for over 15 years now: https://github.com/twbs/bootstrap/tree/main/js/tests.

Here are their unit tests for the Modal component: https://github.com/twbs/bootstrap/blob/main/js/tests/unit/modal.spec.js.

This is probably our golden standard if you will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test Unit test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants