@@ -30,3 +30,30 @@ describe('helper : ', () => {
3030 expect ( copyState2 . openTabIDs != state2 . openTabIDs ) . toBe ( true ) ;
3131 } ) ;
3232} ) ;
33+ describe ( 'helper.filterArrayUntilFirstValue : ' , ( ) => {
34+ test ( 'filterArrayUntilFirstValue function should work correctly and it may change the original array' , ( ) => {
35+ expect . assertions ( 3 ) ;
36+ const arr = [ '1' , '33' , '2' , '3' , '22' , '4' ] ;
37+ const result1 = helper . filterArrayUntilFirstValue ( arr , ( item , index , _arr ) => {
38+ if ( item . includes ( '3' ) ) {
39+ expect ( _arr ) . toEqual ( arr ) ;
40+ }
41+ return item . includes ( '3' ) ;
42+ } ) ;
43+ expect ( result1 ) . toBe ( '33' ) ;
44+ const result2 = helper . filterArrayUntilFirstValue ( arr , ( item ) => item . includes ( '2' ) , true ) ;
45+ expect ( result2 ) . toBe ( '22' ) ;
46+ } ) ;
47+ test ( 'it may change the original array' , ( ) => {
48+ const arr = [ '1' , '33' , '2' , '3' , '22' , '4' ] ;
49+ const originalArr = [ ...arr ] ;
50+ expect ( originalArr ) . toEqual ( arr ) ;
51+ helper . filterArrayUntilFirstValue ( arr , ( item ) => item . includes ( '2' ) , true ) ;
52+ expect ( originalArr ) . not . toEqual ( arr ) ;
53+ } ) ;
54+ test ( 'it should return null if there is not desired element in the array' , ( ) => {
55+ const arr = [ '1' , '2' ] ;
56+ const result = helper . filterArrayUntilFirstValue ( arr , ( item ) => item > 5 ) ;
57+ expect ( result ) . toBe ( null ) ;
58+ } ) ;
59+ } ) ;
0 commit comments