@@ -455,7 +455,7 @@ describe('Find composition', () => {
455
455
} ) ;
456
456
457
457
describe ( 'Event Handlers' , ( ) => {
458
- it ( 'should listen to "create" events' , ( ) => {
458
+ it ( 'should listen to "create" events' , async ( ) => {
459
459
expect . assertions ( 2 ) ;
460
460
461
461
// given
@@ -474,6 +474,7 @@ describe('Find composition', () => {
474
474
mountComposition ( ( ) => {
475
475
findComposition = useFind ( 'testModels' ) ;
476
476
} ) ;
477
+ await nextTick ( ) ;
477
478
478
479
// when
479
480
emitter . emit ( 'created' , additionalTestModel ) ;
@@ -541,7 +542,7 @@ describe('Find composition', () => {
541
542
expect ( findComposition && findComposition . data . value ) . toContainEqual ( additionalTestModel ) ;
542
543
} ) ;
543
544
544
- it ( 'should ignore "create" events when query is not matching' , ( ) => {
545
+ it ( 'should ignore "create" events when query is not matching' , async ( ) => {
545
546
expect . assertions ( 2 ) ;
546
547
547
548
// given
@@ -560,6 +561,7 @@ describe('Find composition', () => {
560
561
mountComposition ( ( ) => {
561
562
findComposition = useFind ( 'testModels' , ref ( { query : { mood : 'please-do-not-match' } } ) ) ;
562
563
} ) ;
564
+ await nextTick ( ) ;
563
565
564
566
// when
565
567
emitter . emit ( 'created' , additionalTestModel ) ;
@@ -905,6 +907,40 @@ describe('Find composition', () => {
905
907
expect ( findComposition && findComposition . data . value ) . not . toContainEqual ( testModel ) ;
906
908
} ) ;
907
909
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
+
908
944
it ( 'should unload the event handlers' , ( ) => {
909
945
expect . assertions ( 7 ) ;
910
946
@@ -1073,6 +1109,7 @@ describe('Find composition', () => {
1073
1109
findComposition = useFind ( 'testModels' , undefined , { loadAllPages : true } ) ;
1074
1110
} ) ;
1075
1111
await nextTick ( ) ;
1112
+ await nextTick ( ) ;
1076
1113
1077
1114
// then
1078
1115
expect ( serviceFind ) . toHaveBeenCalledTimes ( 2 ) ;
@@ -1113,6 +1150,7 @@ describe('Find composition', () => {
1113
1150
findComposition = useFind ( 'testModels' , undefined , { loadAllPages : true } ) ;
1114
1151
} ) ;
1115
1152
await nextTick ( ) ;
1153
+ await nextTick ( ) ;
1116
1154
1117
1155
// then
1118
1156
expect ( serviceFind ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments