Skip to content

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

Merged
merged 4 commits into from
Feb 27, 2023

Conversation

broccolinisoup
Copy link
Member

Closes https://github.com/github/primer/issues/1823
Closes #2836

Screenshots

No visual changes

Merge checklist

  • Added/updated documentation

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@broccolinisoup broccolinisoup added the skip changeset This change does not need a changelog label Feb 20, 2023
@broccolinisoup broccolinisoup requested review from a team and langermank February 20, 2023 06:54
@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2023

⚠️ No Changeset found

Latest commit: 131c97c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 94.28 KB (0%)
dist/browser.umd.js 94.86 KB (0%)

@broccolinisoup broccolinisoup temporarily deployed to github-pages February 20, 2023 07:00 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2916 February 20, 2023 07:01 Inactive

## 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.
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

@siddharthkp siddharthkp Feb 23, 2023

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 :)

Copy link
Member Author

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)

Copy link
Member

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

Copy link
Member Author

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

@broccolinisoup broccolinisoup temporarily deployed to github-pages February 23, 2023 01:40 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2916 February 23, 2023 01:41 Inactive
@broccolinisoup broccolinisoup temporarily deployed to github-pages February 26, 2023 23:49 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2916 February 26, 2023 23:49 Inactive
@broccolinisoup broccolinisoup added this pull request to the merge queue Feb 27, 2023
Merged via the queue into main with commit b342fae Feb 27, 2023
@broccolinisoup broccolinisoup deleted the getting-started-docs branch February 27, 2023 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip changeset This change does not need a changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add instructions to test React apps built with primer/react
4 participants