@@ -479,6 +479,35 @@ describe('Find composition', () => {
479479 expect ( findComposition && findComposition . data . value ) . toContainEqual ( additionalTestModel ) ;
480480 } ) ;
481481
482+ it ( 'should listen to "create" events when query is undefined' , async ( ) => {
483+ expect . assertions ( 2 ) ;
484+
485+ // given
486+ const emitter = eventHelper ( ) ;
487+ const feathersMock = {
488+ service : ( ) => ( {
489+ find : jest . fn ( ( ) => [ ] ) ,
490+ on : emitter . on ,
491+ off : jest . fn ( ) ,
492+ } ) ,
493+ on : jest . fn ( ) ,
494+ off : jest . fn ( ) ,
495+ } as unknown as Application ;
496+ const useFind = useFindOriginal ( feathersMock ) ;
497+ let findComposition = null as UseFind < TestModel > | null ;
498+ mountComposition ( ( ) => {
499+ findComposition = useFind ( 'testModels' , ref ( { query : undefined } ) ) ;
500+ } ) ;
501+ await nextTick ( ) ;
502+
503+ // when
504+ emitter . emit ( 'created' , additionalTestModel ) ;
505+
506+ // then
507+ expect ( findComposition ) . toBeTruthy ( ) ;
508+ expect ( findComposition && findComposition . data . value ) . toContainEqual ( additionalTestModel ) ;
509+ } ) ;
510+
482511 it ( 'should ignore "create" events when query is not matching' , ( ) => {
483512 expect . assertions ( 2 ) ;
484513
@@ -716,7 +745,7 @@ describe('Find composition', () => {
716745 expect ( findComposition && findComposition . data . value . length ) . toBe ( 0 ) ;
717746 } ) ;
718747
719- it ( 'should listen to "patch" & "update" events and add item from list when query is matching now' , async ( ) => {
748+ it ( 'should listen to "patch" & "update" events and add item to list when query is matching now' , async ( ) => {
720749 expect . assertions ( 4 ) ;
721750
722751 // given
@@ -749,6 +778,39 @@ describe('Find composition', () => {
749778 expect ( findComposition && findComposition . data . value ) . toStrictEqual ( [ changedTestModel ] ) ;
750779 } ) ;
751780
781+ it ( 'should listen to "patch" & "update" events and add item to list when query is undefined' , async ( ) => {
782+ expect . assertions ( 4 ) ;
783+
784+ // given
785+ const emitter = eventHelper ( ) ;
786+ const feathersMock = {
787+ service : ( ) => ( {
788+ find : jest . fn ( ( ) => [ ] ) ,
789+ on : emitter . on ,
790+ off : jest . fn ( ) ,
791+ } ) ,
792+ on : jest . fn ( ) ,
793+ off : jest . fn ( ) ,
794+ } as unknown as Application ;
795+ const useFind = useFindOriginal ( feathersMock ) ;
796+ let findComposition = null as UseFind < TestModel > | null ;
797+ mountComposition ( ( ) => {
798+ findComposition = useFind ( 'testModels' , ref ( { query : undefined } ) ) ;
799+ } ) ;
800+
801+ // before then to ensure that the previous loading procedure is completed
802+ await nextTick ( ) ;
803+ expect ( findComposition && findComposition . isLoading . value ) . toBeFalsy ( ) ;
804+ expect ( findComposition && findComposition . data . value . length ) . toBe ( 0 ) ;
805+
806+ // when
807+ emitter . emit ( 'updated' , changedTestModel ) ;
808+
809+ // then
810+ expect ( findComposition ) . toBeTruthy ( ) ;
811+ expect ( findComposition && findComposition . data . value ) . toStrictEqual ( [ changedTestModel ] ) ;
812+ } ) ;
813+
752814 it ( 'should listen to "remove" events' , async ( ) => {
753815 expect . assertions ( 2 ) ;
754816
0 commit comments