react-intl 6.0.6 → 6.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/index.d.ts +43 -0
  2. package/index.d.ts.map +1 -0
  3. package/index.js +51 -0
  4. package/lib/index.d.ts +43 -0
  5. package/lib/index.d.ts.map +1 -0
  6. package/lib/index.js +26 -0
  7. package/lib/src/components/createFormattedComponent.d.ts +29 -0
  8. package/lib/src/components/createFormattedComponent.d.ts.map +1 -0
  9. package/lib/src/components/createFormattedComponent.js +62 -0
  10. package/lib/src/components/dateTimeRange.d.ts +11 -0
  11. package/lib/src/components/dateTimeRange.d.ts.map +1 -0
  12. package/lib/src/components/dateTimeRange.js +15 -0
  13. package/lib/src/components/injectIntl.d.ts +22 -0
  14. package/lib/src/components/injectIntl.d.ts.map +1 -0
  15. package/lib/src/components/injectIntl.js +29 -0
  16. package/lib/src/components/message.d.ts +12 -0
  17. package/lib/src/components/message.d.ts.map +1 -0
  18. package/lib/src/components/message.js +35 -0
  19. package/lib/src/components/plural.d.ts +15 -0
  20. package/lib/src/components/plural.d.ts.map +1 -0
  21. package/lib/src/components/plural.js +26 -0
  22. package/lib/src/components/provider.d.ts +35 -0
  23. package/lib/src/components/provider.d.ts.map +1 -0
  24. package/lib/src/components/provider.js +112 -0
  25. package/lib/src/components/relative.d.ts +12 -0
  26. package/lib/src/components/relative.d.ts.map +1 -0
  27. package/lib/src/components/relative.js +129 -0
  28. package/lib/src/components/useIntl.d.ts +3 -0
  29. package/lib/src/components/useIntl.d.ts.map +1 -0
  30. package/lib/src/components/useIntl.js +8 -0
  31. package/lib/src/types.d.ts +12 -0
  32. package/lib/src/types.d.ts.map +1 -0
  33. package/lib/src/types.js +1 -0
  34. package/lib/src/utils.d.ts +14 -0
  35. package/lib/src/utils.d.ts.map +1 -0
  36. package/lib/src/utils.js +43 -0
  37. package/package.json +9 -9
  38. package/react-intl.iife.js +4688 -0
  39. package/src/components/createFormattedComponent.d.ts +29 -0
  40. package/src/components/createFormattedComponent.d.ts.map +1 -0
  41. package/src/components/createFormattedComponent.js +69 -0
  42. package/src/components/dateTimeRange.d.ts +11 -0
  43. package/src/components/dateTimeRange.d.ts.map +1 -0
  44. package/src/components/dateTimeRange.js +17 -0
  45. package/src/components/injectIntl.d.ts +22 -0
  46. package/src/components/injectIntl.d.ts.map +1 -0
  47. package/src/components/injectIntl.js +33 -0
  48. package/src/components/message.d.ts +12 -0
  49. package/src/components/message.d.ts.map +1 -0
  50. package/src/components/message.js +37 -0
  51. package/src/components/plural.d.ts +15 -0
  52. package/src/components/plural.d.ts.map +1 -0
  53. package/src/components/plural.js +29 -0
  54. package/src/components/provider.d.ts +35 -0
  55. package/src/components/provider.d.ts.map +1 -0
  56. package/src/components/provider.js +116 -0
  57. package/src/components/relative.d.ts +12 -0
  58. package/src/components/relative.d.ts.map +1 -0
  59. package/src/components/relative.js +131 -0
  60. package/src/components/useIntl.d.ts +3 -0
  61. package/src/components/useIntl.d.ts.map +1 -0
  62. package/src/components/useIntl.js +12 -0
  63. package/src/types.d.ts +12 -0
  64. package/src/types.d.ts.map +1 -0
  65. package/src/types.js +2 -0
  66. package/src/utils.d.ts +14 -0
  67. package/src/utils.d.ts.map +1 -0
  68. package/src/utils.js +49 -0
  69. package/BUILD +0 -130
  70. package/CHANGELOG.md +0 -1384
  71. package/example-sandboxes/rescripts/.rescriptsrc.js +0 -28
  72. package/example-sandboxes/rescripts/package-lock.json +0 -18035
  73. package/example-sandboxes/rescripts/package.json +0 -35
  74. package/example-sandboxes/rescripts/public/index.html +0 -42
  75. package/example-sandboxes/rescripts/src/App.tsx +0 -16
  76. package/example-sandboxes/rescripts/src/index.tsx +0 -5
  77. package/example-sandboxes/rescripts/src/react-app-env.d.ts +0 -1
  78. package/example-sandboxes/rescripts/src/styles.css +0 -4
  79. package/example-sandboxes/rescripts/tsconfig.json +0 -20
  80. package/example-sandboxes/strict-locale-type/.env +0 -1
  81. package/example-sandboxes/strict-locale-type/package-lock.json +0 -14595
  82. package/example-sandboxes/strict-locale-type/package.json +0 -35
  83. package/example-sandboxes/strict-locale-type/src/App.tsx +0 -48
  84. package/example-sandboxes/strict-locale-type/src/index.html +0 -28
  85. package/example-sandboxes/strict-locale-type/src/index.tsx +0 -7
  86. package/example-sandboxes/strict-locale-type/src/styles.css +0 -4
  87. package/example-sandboxes/strict-locale-type/tsconfig.json +0 -7
  88. package/example-sandboxes/strict-message-types/.env +0 -1
  89. package/example-sandboxes/strict-message-types/package-lock.json +0 -14596
  90. package/example-sandboxes/strict-message-types/package.json +0 -35
  91. package/example-sandboxes/strict-message-types/src/App.tsx +0 -31
  92. package/example-sandboxes/strict-message-types/src/index.html +0 -28
  93. package/example-sandboxes/strict-message-types/src/index.tsx +0 -7
  94. package/example-sandboxes/strict-message-types/src/styles.css +0 -4
  95. package/example-sandboxes/strict-message-types/tsconfig.json +0 -7
  96. package/examples/BUILD +0 -70
  97. package/examples/Bug2727.tsx +0 -37
  98. package/examples/HandleChange.tsx +0 -48
  99. package/examples/Hooks.tsx +0 -126
  100. package/examples/Injected.tsx +0 -41
  101. package/examples/Messages.tsx +0 -82
  102. package/examples/StaticTypeSafetyAndCodeSplitting/StaticTypeSafetyAndCodeSplitting.tsx +0 -44
  103. package/examples/StaticTypeSafetyAndCodeSplitting/en.json +0 -3
  104. package/examples/StaticTypeSafetyAndCodeSplitting/intlHelpers.tsx +0 -39
  105. package/examples/StaticTypeSafetyAndCodeSplitting/it.json +0 -3
  106. package/examples/TimeZone.tsx +0 -44
  107. package/examples/advanced/Advanced.tsx +0 -68
  108. package/examples/advanced/compiled-lang/en.json +0 -77
  109. package/examples/advanced/compiled-lang/fr.json +0 -77
  110. package/examples/index.html +0 -20
  111. package/examples/index.tsx +0 -44
  112. package/examples/package.json +0 -20
  113. package/index.ts +0 -127
  114. package/jest.config.js +0 -27
  115. package/src/components/createFormattedComponent.tsx +0 -123
  116. package/src/components/dateTimeRange.tsx +0 -26
  117. package/src/components/injectIntl.tsx +0 -111
  118. package/src/components/message.tsx +0 -73
  119. package/src/components/plural.tsx +0 -45
  120. package/src/components/provider.tsx +0 -196
  121. package/src/components/relative.tsx +0 -192
  122. package/src/components/useIntl.ts +0 -10
  123. package/src/types.ts +0 -29
  124. package/src/utils.ts +0 -77
  125. package/tests/functional/index.ts +0 -18
  126. package/tests/functional/support/build.ts +0 -16
  127. package/tests/functional/support/format.tsx +0 -112
  128. package/tests/perf/index.tsx +0 -196
  129. package/tests/setup.js +0 -10
  130. package/tests/unit/components/__snapshots__/displayName.tsx.snap +0 -19
  131. package/tests/unit/components/__snapshots__/message.tsx.snap +0 -41
  132. package/tests/unit/components/__snapshots__/relative.tsx.snap +0 -11
  133. package/tests/unit/components/__snapshots__/useIntl.tsx.snap +0 -25
  134. package/tests/unit/components/date.tsx +0 -233
  135. package/tests/unit/components/dateTimeRange.tsx +0 -103
  136. package/tests/unit/components/displayName.tsx +0 -57
  137. package/tests/unit/components/message.tsx +0 -509
  138. package/tests/unit/components/number.tsx +0 -198
  139. package/tests/unit/components/plural.tsx +0 -116
  140. package/tests/unit/components/provider.tsx +0 -215
  141. package/tests/unit/components/relative.tsx +0 -263
  142. package/tests/unit/components/time.tsx +0 -242
  143. package/tests/unit/components/useIntl.tsx +0 -64
  144. package/tests/unit/components/withIntl.tsx +0 -66
  145. package/tests/unit/react-intl.ts +0 -88
  146. package/tests/unit/testUtils.tsx +0 -42
  147. package/tsconfig.json +0 -5
@@ -1,242 +0,0 @@
1
- import * as React from 'react'
2
- import {FormattedTime, FormattedTimeParts} from '../../../'
3
- import {mountFormattedComponentWithProvider} from '../testUtils'
4
- import {createIntl} from '../../../src/components/provider'
5
- import {IntlShape} from '@formatjs/intl'
6
- import {render} from '@testing-library/react'
7
-
8
- const mountWithProvider = mountFormattedComponentWithProvider(FormattedTime)
9
- const mountPartsWithProvider =
10
- mountFormattedComponentWithProvider(FormattedTimeParts)
11
-
12
- describe('<FormattedTime>', () => {
13
- let intl: IntlShape<React.ReactNode>
14
- const onError = jest.fn()
15
- beforeEach(() => {
16
- onError.mockClear()
17
- intl = createIntl({
18
- locale: 'en',
19
- onError,
20
- })
21
- })
22
-
23
- it('has a `displayName`', () => {
24
- expect(typeof FormattedTime.displayName).toBe('string')
25
- })
26
-
27
- it('throws when <IntlProvider> is missing from ancestry', () => {
28
- // So it doesn't spam the console
29
- jest.spyOn(console, 'error').mockImplementation(() => {})
30
- expect(() => render(<FormattedTime value={0} />)).toThrow(
31
- '[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
32
- )
33
- })
34
-
35
- it('requires a finite `value` prop', () => {
36
- const {rerenderProps} = mountWithProvider({value: 0}, intl)
37
- expect(onError).not.toHaveBeenCalled()
38
-
39
- rerenderProps(
40
- {
41
- value: NaN,
42
- },
43
- intl
44
- )
45
- expect(onError).toHaveBeenCalledTimes(1)
46
- expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
47
- })
48
-
49
- it('renders a formatted time in a <>', () => {
50
- const date = new Date()
51
-
52
- const {getByTestId} = mountWithProvider({value: date}, intl)
53
-
54
- expect(getByTestId('comp')).toHaveTextContent(intl.formatTime(date))
55
- })
56
-
57
- it('renders a formatted time w/o textComponent', () => {
58
- const date = new Date()
59
-
60
- const {getByTestId} = mountWithProvider(
61
- {value: date},
62
- {
63
- ...intl,
64
- // @ts-ignore
65
- textComponent: null,
66
- }
67
- )
68
-
69
- expect(getByTestId('comp')).toHaveTextContent(intl.formatTime(date))
70
- })
71
-
72
- it('accepts valid Intl.DateTimeFormat options as props', () => {
73
- const date = Date.now()
74
- const options: Intl.DateTimeFormatOptions = {hour: '2-digit'}
75
-
76
- const {getByTestId} = mountWithProvider({value: date, ...options}, intl)
77
-
78
- expect(getByTestId('comp')).toHaveTextContent(
79
- intl.formatTime(date, options)
80
- )
81
- })
82
-
83
- it('falls back and warns on invalid Intl.DateTimeFormat options', () => {
84
- const date = new Date()
85
-
86
- const {getByTestId} = mountWithProvider(
87
- // @ts-expect-error invalid for testing
88
- {value: date, hour: 'invalid'},
89
- intl
90
- )
91
-
92
- expect(getByTestId('comp')).toHaveTextContent(String(date))
93
- expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
94
- expect(onError).toHaveBeenCalledTimes(1)
95
- })
96
-
97
- it('accepts `format` prop', () => {
98
- intl = createIntl({
99
- onError: () => {},
100
- locale: 'en',
101
- formats: {
102
- time: {
103
- 'hour-only': {
104
- hour: '2-digit',
105
- hour12: false,
106
- },
107
- },
108
- },
109
- })
110
-
111
- const date = Date.now()
112
- const format = 'hour-only'
113
-
114
- const {getByTestId} = mountWithProvider({value: date, format}, intl)
115
-
116
- expect(getByTestId('comp')).toHaveTextContent(
117
- intl.formatTime(date, {format})
118
- )
119
- })
120
-
121
- it('supports function-as-child pattern', () => {
122
- const date = Date.now()
123
-
124
- const spy = jest.fn().mockImplementation(() => <b data-testid="b">Jest</b>)
125
- const {getByTestId} = mountWithProvider({value: date, children: spy}, intl)
126
-
127
- expect(getByTestId('b').tagName).toBe('B')
128
- expect(getByTestId('comp')).toHaveTextContent('Jest')
129
-
130
- expect(spy).toHaveBeenCalledTimes(1)
131
- expect(spy.mock.calls[0]).toEqual([intl.formatTime(date)])
132
- })
133
- })
134
-
135
- describe('<FormattedTimeParts>', () => {
136
- let intl: IntlShape<React.ReactNode>
137
- const children = jest.fn(
138
- parts => (Array.isArray(parts) && parts[0] && parts[0].value) || null
139
- )
140
- const onError = jest.fn()
141
- beforeEach(() => {
142
- onError.mockClear()
143
- intl = createIntl({
144
- locale: 'en',
145
- onError,
146
- })
147
- children.mockClear()
148
- })
149
-
150
- it('has a `displayName`', () => {
151
- expect(FormattedTimeParts.displayName).toBe('FormattedTimeParts')
152
- })
153
-
154
- it('throws when <IntlProvider> is missing from ancestry', () => {
155
- // So it doesn't spam the console
156
- jest.spyOn(console, 'error').mockImplementation(() => {})
157
- expect(() =>
158
- render(<FormattedTimeParts value={0} children={children} />)
159
- ).toThrow(
160
- '[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
161
- )
162
- })
163
-
164
- it('requires a finite `value` prop', () => {
165
- const {rerenderProps} = mountPartsWithProvider({value: 0, children}, intl)
166
- expect(onError).not.toHaveBeenCalled()
167
-
168
- rerenderProps(
169
- {
170
- children,
171
- value: NaN,
172
- },
173
- intl
174
- )
175
- expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
176
- expect(onError).toHaveBeenCalledTimes(1)
177
- })
178
-
179
- it('accepts valid Intl.DateTimeFormat options as props', () => {
180
- const date = new Date(1567130870626)
181
- const options: Intl.DateTimeFormatOptions = {hour: '2-digit'}
182
-
183
- mountPartsWithProvider({value: date, children, ...options}, intl)
184
-
185
- expect(children.mock.calls[0][0]).toEqual(
186
- intl.formatTimeToParts(date, options)
187
- )
188
- })
189
-
190
- it('renders a string date', () => {
191
- const date = new Date()
192
-
193
- mountPartsWithProvider({value: date.toISOString(), children}, intl)
194
-
195
- expect(children.mock.calls[0][0]).toEqual(intl.formatTimeToParts(date))
196
- })
197
-
198
- it('renders date 0 if value is ""', () => {
199
- const date = new Date(0)
200
-
201
- mountPartsWithProvider({value: '', children}, intl)
202
-
203
- expect(children.mock.calls[0][0]).toEqual(intl.formatTimeToParts(date))
204
- })
205
-
206
- it('falls back and warns on invalid Intl.DateTimeFormat options', () => {
207
- const date = new Date(1567130870626)
208
-
209
- // @ts-expect-error invalid for testing
210
- mountPartsWithProvider({value: date, hour: 'invalid', children}, intl)
211
- expect(children.mock.calls[0][0]).toEqual(
212
- // @ts-expect-error invalid for testing
213
- intl.formatTimeToParts(date, {hour: 'invalid'})
214
- )
215
- expect(onError.mock.calls[0][0].code).toBe('FORMAT_ERROR')
216
- expect(onError).toHaveBeenCalledTimes(2)
217
- })
218
-
219
- it('accepts `format` prop', () => {
220
- intl = createIntl({
221
- onError: () => {},
222
- locale: 'en',
223
- formats: {
224
- time: {
225
- 'hour-only': {
226
- hour: '2-digit',
227
- hour12: false,
228
- },
229
- },
230
- },
231
- })
232
-
233
- const date = new Date(1567130870626)
234
- const format = 'hour-only'
235
-
236
- mountPartsWithProvider({value: date, format, children}, intl)
237
-
238
- expect(children.mock.calls[0][0]).toEqual(
239
- intl.formatTimeToParts(date, {format})
240
- )
241
- })
242
- })
@@ -1,64 +0,0 @@
1
- import * as React from 'react'
2
- import {render} from '@testing-library/react'
3
- import {IntlProvider} from '../../../'
4
- import useIntl from '../../../src/components/useIntl'
5
-
6
- const FunctionComponent = ({spy}: {spy?: Function}) => {
7
- const hookReturns = useIntl()
8
- spy!(hookReturns.locale)
9
- return null
10
- }
11
-
12
- const FC = () => {
13
- const {formatNumber} = useIntl()
14
- return formatNumber(10000, {style: 'currency', currency: 'USD'}) as any
15
- }
16
-
17
- describe('useIntl() hook', () => {
18
- it('throws when <IntlProvider> is missing from ancestry', () => {
19
- // So it doesn't spam the console
20
- jest.spyOn(console, 'error').mockImplementation(() => {})
21
- expect(() => render(<FunctionComponent />)).toThrow(
22
- '[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
23
- )
24
- })
25
-
26
- it('hooks onto the intl context', () => {
27
- const spy = jest.fn()
28
- render(
29
- <IntlProvider locale="en">
30
- <FunctionComponent spy={spy} />
31
- </IntlProvider>
32
- )
33
-
34
- expect(spy).toHaveBeenCalledWith('en')
35
- })
36
-
37
- it('should work when switching locale on provider', () => {
38
- const {rerender, getByTestId} = render(
39
- <IntlProvider locale="en">
40
- <span data-testid="comp">
41
- <FC />
42
- </span>
43
- </IntlProvider>
44
- )
45
- expect(getByTestId('comp')).toMatchSnapshot()
46
- rerender(
47
- <IntlProvider locale="es">
48
- <span data-testid="comp">
49
- <FC />
50
- </span>
51
- </IntlProvider>
52
- )
53
- expect(getByTestId('comp')).toMatchSnapshot()
54
- rerender(
55
- <IntlProvider locale="en">
56
- <span data-testid="comp">
57
- <FC />
58
- </span>
59
- </IntlProvider>
60
- )
61
-
62
- expect(getByTestId('comp')).toMatchSnapshot()
63
- })
64
- })
@@ -1,66 +0,0 @@
1
- import * as React from 'react'
2
- import IntlProvider from '../../../src/components/provider'
3
- import injectIntl, {
4
- WrappedComponentProps,
5
- } from '../../../src/components/injectIntl'
6
- import {render} from '@testing-library/react'
7
- import {IntlShape} from '@formatjs/intl'
8
-
9
- const mountWithProvider = (el: JSX.Element) =>
10
- render(<IntlProvider locale="en">{el}</IntlProvider>)
11
-
12
- describe('injectIntl()', () => {
13
- let Wrapped: React.FC<WrappedComponentProps>
14
-
15
- beforeEach(() => {
16
- Wrapped = ({intl}: {intl: IntlShape<React.ReactNode>}) => (
17
- <div data-testid="comp">{JSON.stringify(intl)}</div>
18
- )
19
- Wrapped.displayName = 'Wrapped'
20
- // @ts-ignore
21
- Wrapped.someNonReactStatic = {
22
- foo: true,
23
- }
24
- })
25
-
26
- it('allows introspection access to the wrapped component', () => {
27
- expect(injectIntl(Wrapped).WrappedComponent).toBe(Wrapped)
28
- })
29
-
30
- it('hoists non-react statics', () => {
31
- expect((injectIntl(Wrapped) as any).someNonReactStatic.foo).toBe(true)
32
- })
33
-
34
- describe('displayName', () => {
35
- it('is descriptive by default', () => {
36
- expect(injectIntl(() => null).displayName).toBe('injectIntl(Component)')
37
- })
38
-
39
- it("includes `WrappedComponent`'s `displayName`", () => {
40
- Wrapped.displayName = 'Foo'
41
- expect(injectIntl(Wrapped).displayName).toBe('injectIntl(Foo)')
42
- })
43
- })
44
-
45
- it('throws when <IntlProvider> is missing from ancestry', () => {
46
- // So it doesn't spam the console
47
- jest.spyOn(console, 'error').mockImplementation(() => {})
48
- const Injected = injectIntl(Wrapped)
49
-
50
- expect(() => render(<Injected />)).toThrow(
51
- '[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.'
52
- )
53
- })
54
-
55
- it('propagates all props to <WrappedComponent>', () => {
56
- const Injected = injectIntl(Wrapped) as any
57
- const props = {
58
- foo: 'bar',
59
- }
60
-
61
- const {getByTestId} = mountWithProvider(<Injected {...props} />)
62
- expect(getByTestId('comp')).toHaveTextContent(
63
- '{"formats":{},"messages":{},"defaultLocale":"en","defaultFormats":{},"fallbackOnEmptyString":true,"locale":"en","formatters":{}}'
64
- )
65
- })
66
- })
@@ -1,88 +0,0 @@
1
- import * as ReactIntl from '../../'
2
- import * as ts from 'typescript'
3
- import fs from 'fs'
4
- import lexer from 'cjs-module-lexer'
5
- import path from 'path'
6
-
7
- describe('react-intl', () => {
8
- describe('exports', () => {
9
- it('exports `defineMessages`', () => {
10
- expect(typeof ReactIntl.defineMessages).toBe('function')
11
- })
12
-
13
- it('exports `defineMessage`', () => {
14
- expect(typeof ReactIntl.defineMessage).toBe('function')
15
- })
16
-
17
- it('exports `injectIntl`', () => {
18
- expect(typeof ReactIntl.injectIntl).toBe('function')
19
- })
20
-
21
- it('exports `useIntl`', () => {
22
- expect(typeof ReactIntl.useIntl).toBe('function')
23
- })
24
-
25
- describe('React Components', () => {
26
- it('exports `IntlProvider`', () => {
27
- expect(typeof ReactIntl.IntlProvider).toBe('function')
28
- })
29
-
30
- it('exports `FormattedDate`', () => {
31
- expect(typeof ReactIntl.FormattedDate).toBe('function')
32
- })
33
-
34
- it('exports `FormattedTime`', () => {
35
- expect(typeof ReactIntl.FormattedTime).toBe('function')
36
- })
37
-
38
- it('exports `FormattedNumber`', () => {
39
- expect(typeof ReactIntl.FormattedNumber).toBe('function')
40
- })
41
-
42
- it('exports `FormattedDateParts`', () => {
43
- expect(typeof ReactIntl.FormattedDateParts).toBe('function')
44
- })
45
-
46
- it('exports `FormattedTimeParts`', () => {
47
- expect(typeof ReactIntl.FormattedTimeParts).toBe('function')
48
- })
49
-
50
- it('exports `FormattedNumberParts`', () => {
51
- expect(typeof ReactIntl.FormattedNumberParts).toBe('function')
52
- })
53
-
54
- it('exports `FormattedRelativeTime`', () => {
55
- expect(typeof ReactIntl.FormattedRelativeTime).toBe('function')
56
- })
57
-
58
- it('exports `FormattedPlural`', () => {
59
- expect(typeof ReactIntl.FormattedPlural).toBe('function')
60
- })
61
-
62
- it('exports `FormattedMessage`', () => {
63
- expect(typeof ReactIntl.FormattedMessage).toBe('object')
64
- })
65
-
66
- it('exports `FormattedDisplayNames`', () => {
67
- expect(typeof ReactIntl.FormattedDisplayName).toBe('function')
68
- })
69
- })
70
- })
71
- describe('static analysis of named exports ', () => {
72
- // Parse dist file for statically analyzable named exports
73
- const filePath = path.resolve(__dirname, '..', '..', 'index.ts')
74
- const source = fs.readFileSync(filePath, 'utf8')
75
- const {outputText} = ts.transpileModule(source, {
76
- compilerOptions: {
77
- esModuleInterop: true,
78
- module: ts.ModuleKind.CommonJS,
79
- },
80
- })
81
- const parsed = lexer.parse(outputText)
82
- const keys = Object.keys(ReactIntl)
83
-
84
- it.each(keys)('has named export "%s"', key => {
85
- expect(parsed.exports).toContain(key)
86
- })
87
- })
88
- })
@@ -1,42 +0,0 @@
1
- import * as React from 'react'
2
- import Provider from '../../src/components/provider'
3
- import {render} from '@testing-library/react'
4
- import type {IntlConfig} from '../../src/types'
5
-
6
- export function mountFormattedComponentWithProvider<P>(
7
- Comp: React.ComponentType<P>
8
- ) {
9
- return (
10
- props: P & {children?(nodes: React.ReactNode[]): React.ReactNode},
11
- providerProps: IntlConfig = {locale: 'en'}
12
- ) => {
13
- const result = render(
14
- <React.StrictMode>
15
- <Provider {...providerProps}>
16
- <span data-testid="comp">
17
- <Comp {...props} />
18
- </span>
19
- </Provider>
20
- </React.StrictMode>
21
- )
22
-
23
- const {rerender} = result
24
- const rerenderProps = (
25
- newProps: P & {
26
- children?(nodes: React.ReactNode[]): React.ReactNode
27
- } = props,
28
- newProviderProps: IntlConfig = providerProps
29
- ) =>
30
- rerender(
31
- <React.StrictMode>
32
- <Provider {...newProviderProps}>
33
- <span data-testid="comp">
34
- <Comp {...newProps} />
35
- </span>
36
- </Provider>
37
- </React.StrictMode>
38
- )
39
-
40
- return {...result, rerenderProps}
41
- }
42
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- // @generated
2
- {
3
- // This is purely for IDE, not for compilation
4
- "extends": "../../tsconfig.json"
5
- }