@@ -455,7 +455,7 @@ describe('Find composition', () => {
455455 } ) ;
456456
457457 describe ( 'Event Handlers' , ( ) => {
458- it ( 'should listen to "create" events' , ( ) => {
458+ it ( 'should listen to "create" events' , async ( ) => {
459459 expect . assertions ( 2 ) ;
460460
461461 // given
@@ -474,6 +474,7 @@ describe('Find composition', () => {
474474 mountComposition ( ( ) => {
475475 findComposition = useFind ( 'testModels' ) ;
476476 } ) ;
477+ await nextTick ( ) ;
477478
478479 // when
479480 emitter . emit ( 'created' , additionalTestModel ) ;
@@ -541,7 +542,7 @@ describe('Find composition', () => {
541542 expect ( findComposition && findComposition . data . value ) . toContainEqual ( additionalTestModel ) ;
542543 } ) ;
543544
544- it ( 'should ignore "create" events when query is not matching' , ( ) => {
545+ it ( 'should ignore "create" events when query is not matching' , async ( ) => {
545546 expect . assertions ( 2 ) ;
546547
547548 // given
@@ -560,6 +561,7 @@ describe('Find composition', () => {
560561 mountComposition ( ( ) => {
561562 findComposition = useFind ( 'testModels' , ref ( { query : { mood : 'please-do-not-match' } } ) ) ;
562563 } ) ;
564+ await nextTick ( ) ;
563565
564566 // when
565567 emitter . emit ( 'created' , additionalTestModel ) ;
@@ -905,6 +907,40 @@ describe('Find composition', () => {
905907 expect ( findComposition && findComposition . data . value ) . not . toContainEqual ( testModel ) ;
906908 } ) ;
907909
910+ it ( 'should cache events when still loading' , async ( ) => {
911+ expect . assertions ( 4 ) ;
912+
913+ // given
914+ const emitter = eventHelper ( ) ;
915+ const feathersMock = {
916+ service : ( ) => ( {
917+ find : vi . fn ( ( ) => [ additionalTestModel2 , testModel ] ) ,
918+ on : emitter . on ,
919+ off : vi . fn ( ) ,
920+ } ) ,
921+ on : vi . fn ( ) ,
922+ off : vi . fn ( ) ,
923+ } as unknown as Application ;
924+ const useFind = useFindOriginal ( feathersMock ) ;
925+ let findComposition = null as UseFind < TestModel > | null ;
926+ mountComposition ( ( ) => {
927+ findComposition = useFind ( 'testModels' ) ;
928+ } ) ;
929+
930+ // when
931+ emitter . emit ( 'updated' , changedTestModel ) ;
932+ emitter . emit ( 'created' , additionalTestModel ) ;
933+ emitter . emit ( 'removed' , additionalTestModel2 ) ;
934+ await nextTick ( ) ;
935+ await nextTick ( ) ;
936+
937+ // then
938+ expect ( findComposition ) . toBeTruthy ( ) ;
939+ expect ( findComposition && findComposition . data . value ) . toHaveLength ( 2 ) ;
940+ expect ( findComposition && findComposition . data . value [ 0 ] ) . toStrictEqual ( changedTestModel ) ;
941+ expect ( findComposition && findComposition . data . value [ 1 ] ) . toStrictEqual ( additionalTestModel ) ;
942+ } ) ;
943+
908944 it ( 'should unload the event handlers' , ( ) => {
909945 expect . assertions ( 7 ) ;
910946
@@ -1073,6 +1109,7 @@ describe('Find composition', () => {
10731109 findComposition = useFind ( 'testModels' , undefined , { loadAllPages : true } ) ;
10741110 } ) ;
10751111 await nextTick ( ) ;
1112+ await nextTick ( ) ;
10761113
10771114 // then
10781115 expect ( serviceFind ) . toHaveBeenCalledTimes ( 2 ) ;
@@ -1113,6 +1150,7 @@ describe('Find composition', () => {
11131150 findComposition = useFind ( 'testModels' , undefined , { loadAllPages : true } ) ;
11141151 } ) ;
11151152 await nextTick ( ) ;
1153+ await nextTick ( ) ;
11161154
11171155 // then
11181156 expect ( serviceFind ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments