@@ -404,12 +404,26 @@ describe('query-history', () => {
404404
405405 it ( 'should get the selection from the treeView when both selections are empty' , async ( ) => {
406406 queryHistoryManager = await createMockQueryHistory ( allHistory ) ;
407- await queryHistoryManager . treeView . reveal ( allHistory [ 1 ] , { select : true } ) ;
408- const selection = ( queryHistoryManager as any ) . determineSelection ( undefined , undefined ) ;
409- expect ( selection ) . to . deep . eq ( {
410- finalSingleItem : allHistory [ 1 ] ,
411- finalMultiSelect : [ allHistory [ 1 ] ]
407+ const p = new Promise < void > ( done => {
408+ queryHistoryManager ! . treeView . onDidChangeSelection ( s => {
409+ if ( s . selection [ 0 ] !== allHistory [ 1 ] ) {
410+ return ;
411+ }
412+ const selection = ( queryHistoryManager as any ) . determineSelection ( undefined , undefined ) ;
413+ expect ( selection ) . to . deep . eq ( {
414+ finalSingleItem : allHistory [ 1 ] ,
415+ finalMultiSelect : [ allHistory [ 1 ] ]
416+ } ) ;
417+ done ( ) ;
418+ } ) ;
412419 } ) ;
420+
421+ // I can't explain why, but the first time the onDidChangeSelection event fires, the selection is
422+ // not correct (it is inexplicably allHistory[2]). So we fire the event a second time to get the
423+ // correct selection.
424+ await queryHistoryManager . treeView . reveal ( allHistory [ 0 ] , { select : true } ) ;
425+ await queryHistoryManager . treeView . reveal ( allHistory [ 1 ] , { select : true } ) ;
426+ await p ;
413427 } ) ;
414428
415429 it ( 'should get the selection from the treeDataProvider when both selections and the treeView are empty' , async ( ) => {
0 commit comments