File tree Expand file tree Collapse file tree 2 files changed +28
-26
lines changed Expand file tree Collapse file tree 2 files changed +28
-26
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,34 @@ title: React Intl
8
8
> If you want to combine setupTests with another setup you should check
9
9
> [ ` setup ` ] ( react-testing-library/setup.md )
10
10
11
+ ## Configuring React-Intl Polyfills
12
+
13
+ If you're using React-Intl in your project, and you need to load a locale, you
14
+ must load the Polyfills according to that language.
15
+
16
+ In order to do so, you may use this small setup and/or combine it with other
17
+ setups.
18
+
19
+ ```
20
+ // src/setupTests.js
21
+ import IntlPolyfill from 'intl'
22
+ import 'intl/locale-data/jsonp/pt'
23
+
24
+ const setupTests = () => {
25
+ // https://formatjs.io/guides/runtime-environments/#server
26
+ if (global.Intl) {
27
+ Intl.NumberFormat = IntlPolyfill.NumberFormat
28
+ Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat
29
+ } else {
30
+ global.Intl = IntlPolyfill
31
+ }
32
+ }
33
+
34
+ setupTests();
35
+ ```
36
+
37
+ A complete example:
38
+
11
39
``` jsx
12
40
import React from ' react'
13
41
import ' jest-dom/extend-expect'
Original file line number Diff line number Diff line change @@ -226,29 +226,3 @@ mocha --require jsdom-global/register
226
226
Note, depending on the version of Node you're running, you may also need to
227
227
install @babel/polyfill (if you're using babel 7) or babel-polyfill (for babel
228
228
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
- ```
You can’t perform that action at this time.
0 commit comments