File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -158,13 +158,7 @@ export class I18n {
158
158
* Loads the language.
159
159
*/
160
160
load ( ) : void {
161
- const lang = this . getActiveLanguage ( )
162
- if ( isServer ) {
163
- this . loadLanguage ( lang )
164
- this . options . onLoad ( lang )
165
- } else {
166
- this . loadLanguageAsync ( lang ) . then ( this . options . onLoad )
167
- }
161
+ this [ isServer ? 'loadLanguage' : 'loadLanguageAsync' ] ( this . getActiveLanguage ( ) )
168
162
}
169
163
170
164
/**
@@ -312,6 +306,7 @@ export class I18n {
312
306
}
313
307
}
314
308
309
+ this . options . onLoad ( lang )
315
310
return lang
316
311
}
317
312
Original file line number Diff line number Diff line change @@ -68,3 +68,19 @@ it('allows resetting all data', async () => {
68
68
expect ( i18n . getActiveLanguage ( ) ) . toBe ( 'en' )
69
69
expect ( i18n . trans ( 'Welcome!' ) ) . toBe ( 'Welcome!' )
70
70
} )
71
+
72
+ it ( 'calls onLoad when loaded' , async ( ) => {
73
+ const onLoadFunction = jest . fn ( )
74
+
75
+ const i18n = new I18n ( {
76
+ lang : 'pt' ,
77
+ resolve : lang => import ( `./fixtures/lang/${ lang } .json` ) ,
78
+ onLoad : onLoadFunction
79
+ } )
80
+
81
+ await i18n . loadLanguageAsync ( 'en' )
82
+
83
+ expect ( onLoadFunction ) . toHaveBeenCalledTimes ( 2 )
84
+ expect ( onLoadFunction ) . toHaveBeenCalledWith ( 'en' )
85
+ expect ( onLoadFunction ) . toHaveBeenCalledWith ( 'pt' )
86
+ } )
You can’t perform that action at this time.
0 commit comments