Skip to content

Commit fae141a

Browse files
alexkrolickKent C. Dodds
authored and
Kent C. Dodds
committed
docs: show CJS workaround for #169 (#179)
<!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar with and follow the Code of Conduct for this project (found in the CODE_OF_CONDUCT.md file). Also, please make sure you're familiar with and follow the instructions in the contributing guidelines (found in the CONTRIBUTING.md file). If you're new to contributing to open source projects, you might find this free video course helpful: http://kcd.im/pull-request Please fill out the information below to expedite the review and (hopefully) merge of your pull request! --> <!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: <!-- Why are these changes necessary? --> **Why**: <!-- How were these changes implemented? --> **How**: <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> - [ ] Documentation - [ ] Tests - [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> - [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments -->
1 parent 57dd63d commit fae141a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,34 @@ module.exports = {
272272
}
273273
```
274274

275+
276+
#### Export Issue with Babel Versions Lower Than 7
277+
278+
Babel versions lower than 7 throw an error when trying to override the named export
279+
in the example above. (See
280+
[#169](https://github.com/kentcdodds/react-testing-library/issues/169).)
281+
282+
<details>
283+
<summary>Workaround</summary>
284+
285+
You can use CommonJS modules instead of ES modules, which should work in Node:
286+
287+
```js
288+
// test-utils.js
289+
const rtl = require('react-testing-library')
290+
291+
const customRender = (node, ...options) => {
292+
return rtl.render(<Something>{node}</Something>)
293+
}
294+
295+
module.exports = {
296+
...rtl,
297+
render: customRender,
298+
}
299+
```
300+
301+
</details>
302+
275303
## Usage
276304

277305
### `render`

0 commit comments

Comments
 (0)