@@ -204,6 +204,53 @@ describe('TranslateService', () => {
204204 } ) ;
205205 } ) ;
206206
207+ it ( 'should be able to get a stream array' , ( done : Function ) => {
208+ let tr = { "TEST" : "This is a test" , "TEST2" : "This is a test2" } ;
209+ translate . setTranslation ( 'en' , tr ) ;
210+ translate . use ( 'en' ) ;
211+
212+ translate . getStreamOnTranslationChange ( [ 'TEST' , 'TEST2' ] ) . subscribe ( ( res : any ) => {
213+ expect ( res ) . toEqual ( tr ) ;
214+ done ( ) ;
215+ } ) ;
216+ } ) ;
217+
218+ it ( 'should initially return the same value for getStreamOnTranslationChange and non-streaming get' , ( done : Function ) => {
219+ translations = { "TEST" : "This is a test" } ;
220+ translate . use ( 'en' ) ;
221+
222+ zip ( translate . getStreamOnTranslationChange ( 'TEST' ) , translate . get ( 'TEST' ) ) . subscribe ( ( value : [ string , string ] ) => {
223+ const [ streamed , nonStreamed ] = value ;
224+ expect ( streamed ) . toEqual ( 'This is a test' ) ;
225+ expect ( streamed ) . toEqual ( nonStreamed ) ;
226+ done ( ) ;
227+ } ) ;
228+ } ) ;
229+
230+ it ( 'should be able to stream a translation on translation change' , ( done : Function ) => {
231+ translations = { "TEST" : "This is a test" } ;
232+ translate . use ( 'en' ) ;
233+
234+ translate . getStreamOnTranslationChange ( 'TEST' ) . pipe ( take ( 3 ) , toArray ( ) ) . subscribe ( ( res : string [ ] ) => {
235+ const expected = [ 'This is a test' , 'I changed the test value!' , 'I changed it again!' ] ;
236+ expect ( res ) . toEqual ( expected ) ;
237+ done ( ) ;
238+ } ) ;
239+ translate . setTranslation ( 'en' , { "TEST" : "I changed the test value!" } ) ;
240+ translate . setTranslation ( 'en' , { "TEST" : "I changed it again!" } ) ;
241+ } ) ;
242+
243+ it ( 'should interpolate the same param into each streamed value when get strean on translation change' , ( done : Function ) => {
244+ translations = { "TEST" : "This is a test {{param}}" } ;
245+ translate . use ( 'en' ) ;
246+
247+ translate . getStreamOnTranslationChange ( 'TEST' , { param : 'with param' } ) . subscribe ( ( res : string [ ] ) => {
248+ const expected = 'This is a test with param' ;
249+ expect ( res ) . toEqual ( expected ) ;
250+ done ( ) ;
251+ } ) ;
252+ } ) ;
253+
207254 it ( 'should be able to stream a translation for the current language' , ( done : Function ) => {
208255 translations = { "TEST" : "This is a test" } ;
209256 translate . use ( 'en' ) ;
0 commit comments