@@ -13,6 +13,7 @@ const testModel: TestModel = { _id: '111', mood: '😀', action: '🧘', categor
13
13
const additionalTestModel : TestModel = { _id : 'aaa' , mood : '🤩' , action : '🏄' , category : 'sport' } ;
14
14
const additionalTestModel2 : TestModel = { _id : 'bbb' , mood : '' , action : '' , category : 'sport' } ;
15
15
const changedTestModel : TestModel = { ...testModel , mood : '😅' , action : '🏋️' , category : 'sport' } ;
16
+ const partialChangedTestModel : Partial < TestModel > = { _id : '111' , action : '🏋️' , category : 'sport' } ;
16
17
const testModels : TestModel [ ] = [ testModel , additionalTestModel2 ] ;
17
18
18
19
describe ( 'Find composition' , ( ) => {
@@ -843,6 +844,38 @@ describe('Find composition', () => {
843
844
expect ( findComposition && findComposition . data . value ) . toStrictEqual ( [ changedTestModel ] ) ;
844
845
} ) ;
845
846
847
+ it ( 'should handle "patch" events with partial responses properly' , async ( ) => {
848
+ expect . assertions ( 2 ) ;
849
+
850
+ // given
851
+ const emitter = eventHelper ( ) ;
852
+ const feathersMock = {
853
+ service : ( ) => ( {
854
+ find : vi . fn ( ( ) => testModels ) ,
855
+ on : emitter . on ,
856
+ off : vi . fn ( ) ,
857
+ } ) ,
858
+ on : vi . fn ( ) ,
859
+ off : vi . fn ( ) ,
860
+ } as unknown as Application ;
861
+ const useFind = useFindOriginal ( feathersMock ) ;
862
+ let findComposition = null as UseFind < TestModel > | null ;
863
+ mountComposition ( ( ) => {
864
+ findComposition = useFind ( 'testModels' ) ;
865
+ } ) ;
866
+ await nextTick ( ) ;
867
+
868
+ // when
869
+ emitter . emit ( 'patched' , partialChangedTestModel ) ;
870
+
871
+ // then
872
+ expect ( findComposition ) . toBeTruthy ( ) ;
873
+ expect ( findComposition && findComposition . data . value ) . toContainEqual ( {
874
+ ...testModel ,
875
+ ...partialChangedTestModel ,
876
+ } ) ;
877
+ } ) ;
878
+
846
879
it ( 'should listen to "remove" events' , async ( ) => {
847
880
expect . assertions ( 2 ) ;
848
881
0 commit comments