@@ -178,6 +178,34 @@ test("find(findIndex) and remove", function () {
178
178
expect ( a . remove ( 20 ) ) . toBe ( false )
179
179
} )
180
180
181
+ test ( "findLast(findLastIndex) and remove" , function ( ) {
182
+ const a = mobx . observable ( [ 10 , 20 , 20 ] )
183
+ let idx = - 1
184
+ function predicate ( item , index ) {
185
+ if ( item === 20 ) {
186
+ idx = index
187
+ return true
188
+ }
189
+ return false
190
+ }
191
+ ; [ ] . findLastIndex ;
192
+ expect ( a . findLast ( predicate ) ) . toBe ( 20 )
193
+ expect ( a . findLastIndex ( predicate ) ) . toBe ( 2 )
194
+ expect ( a . findLast ( predicate ) ) . toBe ( 20 )
195
+
196
+ expect ( a . remove ( 20 ) ) . toBe ( true )
197
+ expect ( a . find ( predicate ) ) . toBe ( 20 )
198
+ expect ( idx ) . toBe ( 1 )
199
+ expect ( a . findIndex ( predicate ) ) . toBe ( 1 )
200
+ idx = - 1
201
+ expect ( a . remove ( 20 ) ) . toBe ( true )
202
+ expect ( a . findLast ( predicate ) ) . toBe ( undefined )
203
+ expect ( idx ) . toBe ( - 1 )
204
+ expect ( a . findLastIndex ( predicate ) ) . toBe ( - 1 )
205
+
206
+ expect ( a . remove ( 20 ) ) . toBe ( false )
207
+ } )
208
+
181
209
test ( "concat should automatically slice observable arrays, #260" , ( ) => {
182
210
const a1 = mobx . observable ( [ 1 , 2 ] )
183
211
const a2 = mobx . observable ( [ 3 , 4 ] )
@@ -630,6 +658,8 @@ test("correct array should be passed to callbacks #2326", () => {
630
658
"filter" ,
631
659
"find" ,
632
660
"findIndex" ,
661
+ "findLast" ,
662
+ "findLastIndex" ,
633
663
"flatMap" ,
634
664
"forEach" ,
635
665
"map" ,
@@ -807,6 +837,31 @@ describe("dehances", () => {
807
837
expect ( [ ...array . values ( ) ] ) . toEqual ( [ ...dehanced . values ( ) ] )
808
838
} )
809
839
840
+ test ( "toReversed" , ( ) => {
841
+ expect ( array . toReversed ( ) ) . toEqual ( dehanced . toReversed ( ) )
842
+ } )
843
+
844
+ test ( "toSorted" , ( ) => {
845
+ expect ( array . toSorted ( ) ) . toEqual ( dehanced . toSorted ( ) )
846
+ } )
847
+
848
+ test ( "toSorted with args" , ( ) => {
849
+ expect ( array . toSorted ( ( a , b ) => a - b ) ) . toEqual ( dehanced . toSorted ( ( a , b ) => a - b ) )
850
+ } )
851
+
852
+ test ( "toSpliced" , ( ) => {
853
+ expect ( array . toSpliced ( 1 , 2 ) ) . toEqual ( dehanced . toSpliced ( 1 , 2 ) )
854
+ } )
855
+
856
+ test ( "with" , ( ) => {
857
+ expect ( array . with ( 1 , 5 ) ) . toEqual ( dehanced . with ( 1 , 5 ) )
858
+ } )
859
+
860
+ test ( "at" , ( ) => {
861
+ expect ( array . at ( 1 ) ) . toEqual ( dehanced . at ( 1 ) )
862
+ expect ( array . at ( - 1 ) ) . toEqual ( dehanced . at ( - 1 ) )
863
+ } )
864
+
810
865
test ( "flat/flatMap" , ( ) => {
811
866
const nestedArray = [ { value : 1 } , [ { value : 2 } , [ { value : 3 } ] ] ]
812
867
const dehancedNestedArray = nestedArray . map ( dehancer )
0 commit comments