Skip to content

Docs: show CJS workaround for #169 #179

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 2 commits into from
Sep 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,34 @@ module.exports = {
}
```


#### Export Issue with Babel Versions Lower Than 7

Babel versions lower than 7 throw an error when trying to override the named export
in the example above. (See
[#169](https://github.com/kentcdodds/react-testing-library/issues/169).)

<details>
<summary>Workaround</summary>

You can use CommonJS modules instead of ES modules, which should work in Node:

```js
// test-utils.js
const rtl = require('react-testing-library')

const customRender = (node, ...options) => {
return rtl.render(<Something>{node}</Something>)
}

module.exports = {
...rtl,
render: customRender,
}
```

</details>

## Usage

### `render`
Expand Down