@@ -85,6 +85,31 @@ export var test_ObservableArray_setItemShouldSetCorrectItem = function () {
85
85
TKUnit . assert ( array . getItem ( 1 ) === 5 , "ObservableArray setItem() should set correct item!" ) ;
86
86
} ;
87
87
88
+ export var test_ObservableArray_setItemShouldRaiseCorrectEvent = function ( ) {
89
+ // <snippet module="data/observable-array" title="observable-array">
90
+ // ### Set item at specified index using setItem(index, item) method and observe change event data.
91
+ // ``` JavaScript
92
+ var index : number ;
93
+ var action : string ;
94
+ var addedCount : number ;
95
+ var removed : Array < number > ;
96
+
97
+ var array = new observableArrayModule . ObservableArray ( [ 1 , 2 , 3 ] ) ;
98
+ array . on ( "change" , ( args ) => {
99
+ index = args . index ; // Index of the changed item.
100
+ action = args . action ; // Action. In this case Update.
101
+ addedCount = args . addedCount ; // Number of added items. In this case 1.
102
+ removed = args . removed ; // Array of removed items. In this case with single item (2).
103
+ } ) ;
104
+ array . setItem ( 1 , 5 ) ;
105
+ // ```
106
+ // </snippet>
107
+ TKUnit . assertEqual ( index , 1 ) ;
108
+ TKUnit . assertEqual ( action , observableArrayModule . ChangeType . Update ) ;
109
+ TKUnit . assertEqual ( addedCount , 1 ) ;
110
+ TKUnit . assertEqual ( removed [ 0 ] , 2 ) ;
111
+ } ;
112
+
88
113
export var test_ObservableArray_concatShouldReturnNewArrayWithNewItemsAtTheEnd = function ( ) {
89
114
// <snippet module="data/observable-array" title="observable-array">
90
115
// ### Use concat() method to combine ObservableArray with array.
@@ -567,7 +592,7 @@ export var test_ObservableArray_lastIndexOfShouldReturnCorrectIndex = function (
567
592
var result = array . lastIndexOf ( "two" ) ;
568
593
// ```
569
594
// </snippet>
570
- TKUnit . assert ( result === 2 , "ObservableArray lastIndexOf() should return correct index!" ) ;
595
+ TKUnit . assert ( result === 2 , "ObservableArray lastIndexOf() should return correct index!" ) ;
571
596
} ;
572
597
573
598
export var test_ObservableArray_lastIndexOfShouldReturnCorrectIndexStartingFrom = function ( ) {
0 commit comments