File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ id : example-react-intl
3
+ title : React Intl
4
+ ---
5
+
6
+ ``` jsx
7
+ import React from ' react'
8
+ import ' jest-dom/extend-expect'
9
+ import { render , cleanup , getByTestId } from ' react-testing-library'
10
+ import { IntlProvider , FormattedDate } from ' react-intl'
11
+ import IntlPolyfill from ' intl'
12
+ import ' intl/locale-data/jsonp/pt'
13
+
14
+ const setupTests = () => {
15
+ // https://formatjs.io/guides/runtime-environments/#server
16
+ if (global .Intl ) {
17
+ Intl .NumberFormat = IntlPolyfill .NumberFormat
18
+ Intl .DateTimeFormat = IntlPolyfill .DateTimeFormat
19
+ } else {
20
+ global .Intl = require (' intl' )
21
+ }
22
+ }
23
+
24
+ const FormatDateView = () => {
25
+ return (
26
+ < div data- testid= " date-display" >
27
+ < FormattedDate
28
+ value= " 2019-03-11"
29
+ timeZone= " utc"
30
+ day= " 2-digit"
31
+ month= " 2-digit"
32
+ year= " numeric"
33
+ / >
34
+ < / div>
35
+ )
36
+ }
37
+
38
+ const renderWithReactIntl = component => {
39
+ return {
40
+ ... render (< IntlProvider locale= " pt" > {component}< / IntlProvider> ),
41
+ }
42
+ }
43
+
44
+ setupTests ()
45
+ afterEach (cleanup)
46
+
47
+ test (' it should render FormattedDate and have a formated pt date' , () => {
48
+ const { container } = renderWithReactIntl (< FormatDateView / > )
49
+ expect (getByTestId (container, ' date-display' )).toHaveTextContent (' 11/03/2019' )
50
+ })
51
+ ```
Original file line number Diff line number Diff line change 12
12
" example-input-event" ,
13
13
" example-update-props" ,
14
14
" example-react-context" ,
15
+ " example-react-intl" ,
15
16
" example-react-redux" ,
16
17
" example-react-router" ,
17
18
" example-reach-router" ,
Original file line number Diff line number Diff line change
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
You can’t perform that action at this time.
0 commit comments