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

Feature: Unit testing #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ayshiff
Copy link
Contributor

@ayshiff ayshiff commented Dec 7, 2020

I felt that avatar-generator needed some testing.
This PR setup the testing environment using bs-jest/bs-react-testing-library and add some tests here and there.
It's not much, but it's always better to have some tests.

Testing a ReasonReact component

bs-react-testing-library + bs-jest

I created a wrapper component called TestId which pass the data-testid (used by react-testing-library) props to its children.
As Reason doesn’t support using props with dashes.
I don't really like this method as it requires adding extra code to the source files, but it works.

1 - Wrap your component using the TestId Wrapper inside your source file
2 - Render your component inside your test file
3 - You can query your elements using your data-testid or using other queries (queryByLabelText, queryByTitle, queryByText...) and fire some events.

Testing a Reason function

bs-jest

NOTE: I had to add a babel.config.js file and a transformIgnorePatterns options in the jest configuration because of the es6 modules (related issue).
I also had to add the preset babel-preset-gatsby because gatsby returned an error during the compilation if I did not specify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant