@@ -156,6 +156,61 @@ describe('createJsonMutation', () => {
156156 ) ;
157157 } ) ;
158158
159+ test ( 'handle 204 No Content response with DELETE method' , async ( ) => {
160+ const mutation = createJsonMutation ( {
161+ request : {
162+ url : 'https://api.salo.com/resource/123' ,
163+ method : 'DELETE' as const ,
164+ } ,
165+ response : { contract : unknownContract } ,
166+ } ) ;
167+
168+ const scope = fork ( {
169+ handlers : [ [ fetchFx , ( ) => new Response ( null , { status : 204 } ) ] ] ,
170+ } ) ;
171+
172+ const { listeners } = watchRemoteOperation ( mutation , scope ) ;
173+
174+ await allSettled ( mutation . start , { scope } ) ;
175+
176+ expect ( listeners . onFailure ) . not . toHaveBeenCalled ( ) ;
177+ expect ( listeners . onSuccess ) . toHaveBeenCalled ( ) ;
178+ expect ( listeners . onSuccess ) . toHaveBeenCalledWith (
179+ expect . objectContaining ( {
180+ result : null ,
181+ params : undefined ,
182+ } )
183+ ) ;
184+ } ) ;
185+
186+ test ( 'handle 204 No Content response with POST method' , async ( ) => {
187+ const mutation = createJsonMutation ( {
188+ request : {
189+ url : 'https://api.salo.com/resource' ,
190+ method : 'POST' as const ,
191+ body : { data : 'test' } ,
192+ } ,
193+ response : { contract : unknownContract } ,
194+ } ) ;
195+
196+ const scope = fork ( {
197+ handlers : [ [ fetchFx , ( ) => new Response ( null , { status : 204 } ) ] ] ,
198+ } ) ;
199+
200+ const { listeners } = watchRemoteOperation ( mutation , scope ) ;
201+
202+ await allSettled ( mutation . start , { scope } ) ;
203+
204+ expect ( listeners . onFailure ) . not . toHaveBeenCalled ( ) ;
205+ expect ( listeners . onSuccess ) . toHaveBeenCalled ( ) ;
206+ expect ( listeners . onSuccess ) . toHaveBeenCalledWith (
207+ expect . objectContaining ( {
208+ result : null ,
209+ params : undefined ,
210+ } )
211+ ) ;
212+ } ) ;
213+
159214 test ( 'cancel json mutation by external clock' , async ( ) => {
160215 const abort = createEvent ( ) ;
161216
0 commit comments