@@ -30,7 +30,7 @@ import { Defer20220824Handler } from "@apollo/client/incremental";
3030import { BatchHttpLink } from "@apollo/client/link/batch-http" ;
3131import { ApolloProvider , useMutation , useQuery } from "@apollo/client/react" ;
3232import { MockLink , MockSubscriptionLink } from "@apollo/client/testing" ;
33- import { spyOnConsole } from "@apollo/client/testing/internal" ;
33+ import { spyOnConsole , wait } from "@apollo/client/testing/internal" ;
3434import { MockedProvider } from "@apollo/client/testing/react" ;
3535import type { DeepPartial } from "@apollo/client/utilities" ;
3636import { invariant } from "@apollo/client/utilities/invariant" ;
@@ -513,6 +513,47 @@ describe("useMutation Hook", () => {
513513 await expect ( takeSnapshot ) . not . toRerender ( ) ;
514514 } ) ;
515515
516+ it ( "does not cause unhandled rejections" , async ( ) => {
517+ const variables = {
518+ description : "Get milk!" ,
519+ } ;
520+
521+ const mocks = [
522+ {
523+ request : {
524+ query : CREATE_TODO_MUTATION ,
525+ variables,
526+ } ,
527+ result : {
528+ errors : [ { message : CREATE_TODO_ERROR } ] ,
529+ } ,
530+ delay : 10 ,
531+ } ,
532+ ] ;
533+
534+ using _disabledAct = disableActEnvironment ( ) ;
535+ const { takeSnapshot, getCurrentSnapshot } =
536+ await renderHookToSnapshotStream (
537+ ( ) => useMutation ( CREATE_TODO_MUTATION , { variables } ) ,
538+ {
539+ wrapper : ( { children } ) => (
540+ < MockedProvider mocks = { mocks } > { children } </ MockedProvider >
541+ ) ,
542+ }
543+ ) ;
544+
545+ await takeSnapshot ( ) ;
546+
547+ const [ createTodo ] = getCurrentSnapshot ( ) ;
548+
549+ // Intentionally don't await this to ensure we don't get unhandled rejections
550+ createTodo ( ) ;
551+ await wait ( 15 ) ;
552+
553+ // No assertions needed. This test fails if the promise throws an
554+ // unhandled rection
555+ } ) ;
556+
516557 it ( `should reject when errorPolicy is 'none'` , async ( ) => {
517558 const variables = {
518559 description : "Get milk!" ,
0 commit comments