@@ -25,6 +25,20 @@ type OnTranslateError = ComponentProps<typeof I18n>['onTranslateError']
2525const isDefaultLocalesSupported = ( locale : string ) : locale is Locales =>
2626 ListLocales . includes ( locale as Locales )
2727
28+ const load = async ( {
29+ locale,
30+ namespace,
31+ } : {
32+ locale : string
33+ namespace : string
34+ } ) =>
35+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
36+ import ( `./locales/namespaces/${ locale } /${ namespace } .json` )
37+
38+ const CustomComponent = ( { children } : { children : ReactNode } ) => (
39+ < p style = { { fontWeight : 'bold' } } > { children } </ p >
40+ )
41+
2842const defaultOnTranslateError : OnTranslateError = ( ) => { }
2943
3044const wrapper =
@@ -148,16 +162,6 @@ describe('i18n hook', () => {
148162 } )
149163
150164 it ( 'should use specific load on useTranslation' , async ( ) => {
151- const load = async ( {
152- locale,
153- namespace,
154- } : {
155- locale : string
156- namespace : string
157- } ) =>
158- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
159- import ( `./locales/namespaces/${ locale } /${ namespace } .json` )
160-
161165 const { result } = renderHook (
162166 ( ) => useTranslation < NamespaceLocale , Locales > ( [ 'user' , 'profile' ] , load ) ,
163167 {
@@ -206,16 +210,6 @@ describe('i18n hook', () => {
206210 } )
207211
208212 it ( "should use specific load and fallback default local if the key doesn't exist" , async ( ) => {
209- const load = async ( {
210- locale,
211- namespace,
212- } : {
213- locale : string
214- namespace : string
215- } ) =>
216- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
217- import ( `./locales/namespaces/${ locale } /${ namespace } .json` )
218-
219213 const { result } = renderHook (
220214 ( ) => useTranslation < NamespaceLocale , Locales > ( [ 'user' ] , load ) ,
221215 {
@@ -272,21 +266,24 @@ describe('i18n hook', () => {
272266 wrapper : wrapper ( { defaultLocale : 'en' } ) ,
273267 } ,
274268 )
275- const CustomComponent = ( { children } : { children : ReactNode } ) => (
276- < p style = { { fontWeight : 'bold' } } > { children } </ p >
277- )
278269
279270 await waitFor ( ( ) => {
280271 expect (
281- result . current . t ( 'with.identifier' , { identifier : < b > My resource</ b > } ) ,
282- ) . toEqual ( [ 'Are you sure you want to delete ' , < b > My resource</ b > , '?' ] )
272+ result . current . t ( 'with.identifier' , {
273+ identifier : < b key = "1" > My resource</ b > ,
274+ } ) ,
275+ ) . toEqual ( [
276+ 'Are you sure you want to delete ' ,
277+ < b key = "1" > My resource</ b > ,
278+ '?' ,
279+ ] )
283280 expect (
284281 result . current . t ( 'with.identifier' , {
285- identifier : < CustomComponent > My resource</ CustomComponent > ,
282+ identifier : < CustomComponent key = "1" > My resource</ CustomComponent > ,
286283 } ) ,
287284 ) . toEqual ( [
288285 'Are you sure you want to delete ' ,
289- < CustomComponent > My resource</ CustomComponent > ,
286+ < CustomComponent key = "1" > My resource</ CustomComponent > ,
290287 '?' ,
291288 ] )
292289 } )
@@ -581,12 +578,12 @@ describe('i18n hook', () => {
581578 currency : 'EUR' ,
582579 style : 'currency' ,
583580 } ) ,
584- ) . toEqual ( '2,00\xa0 €' )
581+ ) . toEqual ( '2,00\u00A0 €' )
585582 } )
586583
587584 expect (
588585 result . current . formatNumber ( 2 , { currency : 'USD' , style : 'currency' } ) ,
589- ) . toEqual ( '2,00\xa0 $US' )
586+ ) . toEqual ( '2,00\u00A0 $US' )
590587 } )
591588
592589 it ( 'should use formatList' , async ( ) => {
0 commit comments