-
Notifications
You must be signed in to change notification settings - Fork 616
Add guidance on testing to the Getting Started
docs
#2916
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
Conversation
|
size-limit report 📦
|
docs/content/getting-started.md
Outdated
|
||
## Testing | ||
|
||
Testing your application with Primer React is no different than testing your application with any other React library. Depending on your test environment and the testing libraries you use, you may need polyfills. For example if you are using `jest`, it runs via Node runtime and using [JSDOM](https://github.com/jsdom/jsdom) as a DOM implementation, so you will need to mock some browser APIs. We have [helpers](https://github.com/primer/react/blob/main/src/utils/test-helpers.tsx) that you can utilize to mock some of these APIs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpful to also add a note/code snippet on how to include this file of test helpers in Jest or would that be better placed somewhere else in the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a great point but I don't think we export the file? I imagined they could copy the mocks they needed from the test-helpers but it would be ideal to import the file. Maybe I am missing something here though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like copying and pasting those mocks is a reasonable approach if we want to avoid increasing the API surface area of Primer React.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One vote for exporting test-helpers, I think copy pasting is a secret trick that we tell people after they ask us why it broke 😅
Update from @joshblack, We already export them, we just didn't document it till now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry yes I just realised we export the file!
Would below be accurate to document?
import "@primer/react/lib-esm/utils/test-helpers"; (For ESM)
import "@primer/react/lib/utils/test-helpers"; (For CommonJS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so! 👍 Example of usage over in memex: https://gh.io/AAjpnug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Just pushed a commit
Closes https://github.com/github/primer/issues/1823
Closes #2836
Screenshots
No visual changes
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.