@@ -113,6 +113,68 @@ describe('default option', () => {
113
113
} )
114
114
} )
115
115
116
+ describe ( 'context fallbackLocale option' , ( ) => {
117
+ test ( 'false' , ( ) => {
118
+ const mockWarn = warn as jest . MockedFunction < typeof warn >
119
+ mockWarn . mockImplementation ( ( ) => { } )
120
+
121
+ const ctx = context ( {
122
+ locale : 'en' ,
123
+ fallbackLocale : false ,
124
+ messages : {
125
+ en : { }
126
+ }
127
+ } )
128
+
129
+ expect ( translate ( ctx , 'hello' ) ) . toEqual ( 'hello' )
130
+ expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toEqual (
131
+ `Not found 'hello' key in 'en' locale messages.`
132
+ )
133
+ } )
134
+
135
+ test ( 'string' , ( ) => {
136
+ const mockWarn = warn as jest . MockedFunction < typeof warn >
137
+ mockWarn . mockImplementation ( ( ) => { } )
138
+
139
+ const ctx = context ( {
140
+ locale : 'en' ,
141
+ fallbackLocale : 'ja' ,
142
+ messages : {
143
+ en : { } ,
144
+ ja : {
145
+ hello : 'こんにちは!'
146
+ }
147
+ }
148
+ } )
149
+
150
+ expect ( translate ( ctx , 'hello' ) ) . toEqual ( 'こんにちは!' )
151
+ expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toEqual (
152
+ `Not found 'hello' key in 'en' locale messages.`
153
+ )
154
+ } )
155
+
156
+ test ( 'array' , ( ) => {
157
+ const mockWarn = warn as jest . MockedFunction < typeof warn >
158
+ mockWarn . mockImplementation ( ( ) => { } )
159
+
160
+ const ctx = context ( {
161
+ locale : 'en' ,
162
+ fallbackLocale : [ 'ja' ] ,
163
+ messages : {
164
+ en : { } ,
165
+ ja : {
166
+ hello : 'こんにちは!'
167
+ }
168
+ }
169
+ } )
170
+
171
+ expect ( translate ( ctx , 'hello' ) ) . toEqual ( 'こんにちは!' )
172
+ expect ( mockWarn . mock . calls [ 0 ] [ 0 ] ) . toEqual (
173
+ `Not found 'hello' key in 'en' locale messages.`
174
+ )
175
+ } )
176
+ } )
177
+
116
178
describe ( 'context missing option' , ( ) => {
117
179
test ( 'not specified missing handler' , ( ) => {
118
180
const mockWarn = warn as jest . MockedFunction < typeof warn >
0 commit comments