Skip to content

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

Merged
merged 10 commits into from
Sep 4, 2018

Conversation

alexkrolick
Copy link
Collaborator

@alexkrolick alexkrolick commented Sep 3, 2018

No description provided.

@alexkrolick alexkrolick changed the title Docs: add setup section to top Docs: add global setup, custom render docs Sep 3, 2018
Copy link
Member

@kentcdodds kentcdodds left a 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
Copy link
Member

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

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

@alexkrolick alexkrolick Sep 4, 2018

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 from create-react-app, this option is set to src/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
Copy link
Member

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

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?

Copy link
Collaborator Author

@alexkrolick alexkrolick Sep 4, 2018

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.

Copy link
Collaborator Author

@alexkrolick alexkrolick Sep 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@kentcdodds kentcdodds left a 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
Copy link
Member

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?

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! Thanks :)

@kentcdodds kentcdodds merged commit a05248e into testing-library:master Sep 4, 2018
@alexkrolick
Copy link
Collaborator Author

🎉

@alexkrolick alexkrolick deleted the setup-section branch September 4, 2018 19:27
@kentcdodds
Copy link
Member

🎉 This PR is included in version 5.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

lucbpz pushed a commit to lucbpz/react-testing-library that referenced this pull request Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants