Skip to content

Commit 8b4b467

Browse files
Improved description and added a React-Intl setup description on setup.
1 parent 236cb3e commit 8b4b467

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

docs/example-react-intl.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ id: example-react-intl
33
title: React Intl
44
---
55

6+
> **Note**
7+
>
8+
> If you want to combine setupTests with another setup you should check
9+
> [`setup`](react-testing-library/setup.md)
10+
611
```jsx
712
import React from 'react'
813
import 'jest-dom/extend-expect'
@@ -36,9 +41,7 @@ const FormatDateView = () => {
3641
}
3742

3843
const renderWithReactIntl = component => {
39-
return {
40-
...render(<IntlProvider locale="pt">{component}</IntlProvider>),
41-
}
44+
return render(<IntlProvider locale="pt">{component}</IntlProvider>)
4245
}
4346

4447
setupTests()

docs/react-testing-library/setup.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,29 @@ mocha --require jsdom-global/register
226226
Note, depending on the version of Node you're running, you may also need to
227227
install @babel/polyfill (if you're using babel 7) or babel-polyfill (for babel
228228
6).
229+
230+
## Configuring React-Intl Polyfills
231+
232+
If you're using React-Intl in your project, and you need to load a locale, you
233+
must load the Polyfills according to that language.
234+
235+
In order to do so, you may use this small setup and/or combine it with other
236+
setups.
237+
238+
```
239+
// src/setupTests.js
240+
import IntlPolyfill from 'intl'
241+
import 'intl/locale-data/jsonp/pt'
242+
243+
const setupTests = () => {
244+
// https://formatjs.io/guides/runtime-environments/#server
245+
if (global.Intl) {
246+
Intl.NumberFormat = IntlPolyfill.NumberFormat
247+
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
248+
} else {
249+
global.Intl = IntlPolyfill
250+
}
251+
}
252+
253+
setupTests();
254+
```

0 commit comments

Comments
 (0)