-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Docs: add global setup, custom render docs #166
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
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.
This is going to be soooo great. Thank you @alexkrolick!
README.md
Outdated
// Act | ||
fireEvent.click(getByText('Load Greeting')) | ||
|
||
// let's wait for our mocked `get` request promise to resolve |
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.
Let's rephrase these comments:
// Let's wait until our mocked `get` request promise resolves and
// the component calls setState and re-renders.
// getByTestId throws an error if it cannot find an element with the given ID
// and waitForElement will wait until the callback doesn't throw an error
README.md
Outdated
To do this with Jest, you can add the | ||
[`setupTestFrameworkScriptFile`](https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string) | ||
option to your Jest config. The setup file can be anywhere, but if you're using | ||
create-react-app, use the default `src/setupTests.js`. |
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.
Change to:
... use the default `src/setupTests.js` (in this case, no configuration changes are necessary).
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.
Not sure I understand "no configuration changes are necessary". Can you clarify?
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 I see. It doesn't require changing the Jest config. I think it can be worded better than that even:
To do this with Jest, you can add the
setupTestFrameworkScriptFile
option to your Jest config.
Note:
If you are using the default setup fromcreate-react-app
, this option is set tosrc/setupTests.js
. You should create this file if it doesn't exist and put the setup code there.
README.md
Outdated
module.exports = { | ||
moduleDirectories: [ | ||
'node_modules', | ||
+ __dirname, // the project root |
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.
Let's make the comment say: "the directory where your test-utils.js
file resides."
I'd prefer to recommend that file exists in a directory called test
rather than at the root of the project.
``` | ||
|
||
```javascript | ||
// jest.setup.js |
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.
Maybe we should recommend putting this file in a directory called test
to avoid overfilling the root directory?
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.
TBH I prefer putting that stuff in root initially and cleaning things up only if it gets overwhelming. Plus, test
sounds like a place to put tests and not just a config directory. Maybe utils
, if anything. But I think it's personal preference how to organize these types of things.
EDIT: I also like jest.setup.js because it appears right after jest.config.js alphabetically if they are in the same folder.
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.
Added a line here showing some alternate location ideas: https://github.com/kentcdodds/react-testing-library/pull/166/files#diff-04c6e90faac2675aa89e2176d2eec7d8R179
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.
This is spectacular. Just one last little thing. Thanks!
README.md
Outdated
`react-testing-library` does not require any configuration to be used (as demonstrated in the example above). However, there are some things you can do to when configuring your testing framework to reduce some boilerplate. In these docs we'll demonstrate configuring Jest, but you should be able to do similar things with any testing framework (react-testing-library does not require that you use Jest). | ||
|
||
|
||
### Globals |
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'm not certain I like the title of this section to be Globals
. Makes it sound like we need to setup global variables or something. Could we instead call this Global Config
or something?
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.
Super! Thanks :)
🎉 |
🎉 This PR is included in version 5.1.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
No description provided.