Skip to content

Commit 742c536

Browse files
authored
Docs: show CJS workaround for testing-library#169
1 parent 57dd63d commit 742c536

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,33 @@ 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 in the example above. (See [bug](https://github.com/kentcdodds/react-testing-library/issues/169).)
279+
280+
<details>
281+
<summary>Workaround</summary>
282+
283+
284+
You can use CommonJS modules instead of ES modules, which should work in Node:
285+
286+
```js
287+
// test-utils.js
288+
const rtl = require('react-testing-library')
289+
290+
const customRender = (node, ...options) => {
291+
return rtl.render(<Something>{node}</Something>)
292+
}
293+
294+
module.exports = {
295+
...rtl,
296+
render: customRender,
297+
}
298+
```
299+
300+
</details>
301+
275302
## Usage
276303

277304
### `render`

0 commit comments

Comments
 (0)