File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,19 @@ describe('SelectionModel', () => {
102
102
expect ( event . added ) . toEqual ( [ 2 ] ) ;
103
103
} ) ;
104
104
105
+ it ( 'should have updated the selected value before emitting the change event' , ( ) => {
106
+ let model = new SelectionModel ( true ) ;
107
+ let spy = jasmine . createSpy ( 'SelectionModel change event' ) ;
108
+
109
+ // Note: this assertion is only here to run the getter.
110
+ expect ( model . selected ) . toEqual ( [ ] ) ;
111
+
112
+ model . onChange ! . subscribe ( ( ) => spy ( model . selected ) ) ;
113
+ model . select ( 1 ) ;
114
+
115
+ expect ( spy ) . toHaveBeenCalledWith ( [ 1 ] ) ;
116
+ } ) ;
117
+
105
118
describe ( 'selection' , ( ) => {
106
119
let model : SelectionModel < any > ;
107
120
let spy : jasmine . Spy ;
Original file line number Diff line number Diff line change @@ -118,8 +118,11 @@ export class SelectionModel<T> {
118
118
119
119
/** Emits a change event and clears the records of selected and deselected values. */
120
120
private _emitChangeEvent ( ) {
121
+ // Clear the selected values so they can be re-cached.
122
+ this . _selected = null ;
123
+
121
124
if ( this . _selectedToEmit . length || this . _deselectedToEmit . length ) {
122
- let eventData = new SelectionChange ( this . _selectedToEmit , this . _deselectedToEmit ) ;
125
+ const eventData = new SelectionChange ( this . _selectedToEmit , this . _deselectedToEmit ) ;
123
126
124
127
if ( this . onChange ) {
125
128
this . onChange . next ( eventData ) ;
@@ -128,8 +131,6 @@ export class SelectionModel<T> {
128
131
this . _deselectedToEmit = [ ] ;
129
132
this . _selectedToEmit = [ ] ;
130
133
}
131
-
132
- this . _selected = null ;
133
134
}
134
135
135
136
/** Selects a value. */
You can’t perform that action at this time.
0 commit comments