在 jest-react 中使用 MockedProvider 会导致错误“查询没有更多的模拟响应”

Posted

技术标签:

【中文标题】在 jest-react 中使用 MockedProvider 会导致错误“查询没有更多的模拟响应”【英文标题】:Using MockedProvider results in error "No more mocked reponses for the query" in jest-react 【发布时间】:2020-08-23 21:29:08 【问题描述】:

我一直在尝试测试一个反应功能组件,它使用 apollo-react 来获取数据。我不断收到错误消息:没有更多的模拟响应查询。我尝试了各种解决方案,但没有任何效果。这是测试用例:

import  mount  from 'enzyme';
import ProcessDetailsPage from '../ProcessDetailsPage';
import  MockedProvider  from '@apollo/react-testing';
import wait from 'waait';
import  BrowserRouter  from 'react-router-dom';
import  GetProcessInstanceByIdDocument, ProcessInstanceState  from '../../../../graphql/types';
// import  act  from 'react-dom/test-utils';

const props = 
  match: 
    params: '8035b580-6ae4-4aa8-9ec0-e18e19809e0blmnop'
  
;

const mocks = [
  
    request: 
      query: GetProcessInstanceByIdDocument,
      variables: 
        id: '201a8a42-043e-375a-9f52-57c804b24db4'
      
    ,
    result: 
      data: 
        ProcessInstances: [
          
            id: '201a8a42-043e-375a-9f52-57c804b24db4',
            processId: 'travels',
            processName: 'travels',
            businessKey: 'MQQ640',
            parentProcessInstanceId: null,
            parentProcessInstance: null,
            roles: [],
            variables:
              '"flight":"flightNumber":"MX555","seat":null,"gate":null,"departure":"2020-05-08T03:30:00.000+05:30","arrival":"2020-05-09T03:30:00.000+05:30","hotel":"name":"Perfect hotel","address":"street":"street","city":"Bengaluru","zipCode":"12345","country":"India","phone":"09876543","bookingNumber":"XX-012345","room":null,"trip":"city":"Bengaluru","country":"India","begin":"2020-05-08T03:30:00.000+05:30","end":"2020-05-09T03:30:00.000+05:30","visaRequired":false,"traveller":"firstName":"Ajay","lastName":"Jaganathan","email":"ajaganat@redhat.com","nationality":"Polish","address":"street":"Bangalore","city":"Bangalore","zipCode":"560093","country":"Poland"',
            state: ProcessInstanceState.Active,
            start: '2020-05-07T06:50:18.274Z',
            lastUpdate: '2020-05-07T06:50:18.502Z',
            end: null,
            addons: [
              'process-management',
              'infinispan-persistence',
              'prometheus-monitoring'
            ],
            endpoint: 'http://localhost:8080/travels',
            serviceUrl: 'http://localhost:8080',
            error: null,
            childProcessInstances: [
              
                id: 'bfde98ed-0cdd-4700-ae87-377f7ec430cd',
                processName: 'HotelBooking',
                businessKey: null
              ,
              
                id: 'e607b2a9-0aca-4788-9623-dd2e156ce9c4',
                processName: 'FlightBooking',
                businessKey: null
              
            ],
            nodes: [
              
                id: '39d5fe7c-4e37-44ce-8d25-05a4a29ec6ea',
                nodeId: '17',
                name: 'Book Hotel',
                enter: '2020-05-07T06:50:18.429Z',
                exit: '2020-05-07T06:50:18.439Z',
                type: 'SubProcessNode',
                definitionId: '_1A708F87-11C0-42A0-A464-0B7E259C426F'
              ,
              
                id: '1d3d7ebe-79ec-4848-b1d6-d7c5a371b4dd',
                nodeId: '8',
                name: 'Confirm travel',
                enter: '2020-05-07T06:50:18.443Z',
                exit: null,
                type: 'HumanTaskNode',
                definitionId: '_2140F05A-364F-40B3-BB7B-B12927065DF8'
              ,
              
                id: '4fc774f5-c429-4b97-8981-bd60d1f59954',
                nodeId: '7',
                name: 'Join',
                enter: '2020-05-07T06:50:18.442Z',
                exit: '2020-05-07T06:50:18.443Z',
                type: 'Join',
                definitionId: '_5D0733B5-53FE-40E9-9900-4CC13419C67A'
              ,
              
                id: '60309b28-1dbe-49c3-b0d8-8cefb86be8b4',
                nodeId: '10',
                name: 'Book Flight',
                enter: '2020-05-07T06:50:18.439Z',
                exit: '2020-05-07T06:50:18.442Z',
                type: 'SubProcessNode',
                definitionId: '_F543B3F0-AB44-4A5B-BF17-8D9DEB505815'
              ,
              
                id: 'efa5a6c0-9470-4405-8609-620bdbfbb6d9',
                nodeId: '2',
                name: 'Book',
                enter: '2020-05-07T06:50:18.428Z',
                exit: '2020-05-07T06:50:18.439Z',
                type: 'Split',
                definitionId: '_175DC79D-C2F1-4B28-BE2D-B583DFABF70D'
              ,
              
                id: 'acc87f1f-e436-4364-b4d3-9069ddb359c9',
                nodeId: '14',
                name: 'Join',
                enter: '2020-05-07T06:50:18.428Z',
                exit: '2020-05-07T06:50:18.428Z',
                type: 'Join',
                definitionId: '_B34ADDEE-DEA5-47C5-A913-F8B85ED5641F'
              ,
              
                id: '6c20729a-3e2b-44c5-af5c-8554f21a7ebf',
                nodeId: '15',
                name: 'is visa required',
                enter: '2020-05-07T06:50:18.427Z',
                exit: '2020-05-07T06:50:18.428Z',
                type: 'Split',
                definitionId: '_5EA95D17-59A6-4567-92DF-74D36CE7F35A'
              ,
              
                id: '3fb92a0a-e88b-45a4-a48b-65f11a679b96',
                nodeId: '5',
                name: 'Visa check',
                enter: '2020-05-07T06:50:18.278Z',
                exit: '2020-05-07T06:50:18.427Z',
                type: 'RuleSetNode',
                definitionId: '_54ABE1ED-61BE-45F9-812C-795A5D4ED35E'
              ,
              
                id: '2860e474-dffc-498c-8731-e6b6f0b5d4d4',
                nodeId: '16',
                name: 'StartProcess',
                enter: '2020-05-07T06:50:18.276Z',
                exit: '2020-05-07T06:50:18.278Z',
                type: 'StartNode',
                definitionId: '_1B11BEC9-402A-4E73-959A-296BD334CAB0'
              
            ]
          
        ]
      
    
  
];

// const waitForComponentToRender = async (wrapper: any) => 
//   await act(async () => 
//     await new Promise(resolve => setTimeout(resolve, 5000));
//     wrapper.update();
//   );
// ;

describe('Process Details Page component', () => 
  it('Sample test case', async () => 
    const wrapper = mount(
      <MockedProvider mocks=mocks addTypename=false>
        <BrowserRouter>
          <ProcessDetailsPage ...props />
        </BrowserRouter>
      </MockedProvider>
    );
     // waitForComponentToRender(wrapper)
     await wait(0);
     wrapper.update()
     console.log(wrapper.debug())
    expect(wrapper).toMatchSnapshot();
  );
);

这是我正在使用的查询:

export const GetProcessInstanceByIdDocument = gql`
  query getProcessInstanceById($id: String) 
    ProcessInstances(where:  id:  equal: $id  ) 
      id
      processId
      processName
      businessKey
      parentProcessInstanceId
      parentProcessInstance 
        id
        processName
        businessKey
      
      roles
      variables
      state
      start
      lastUpdate
      end
      addons
      endpoint
      addons
      serviceUrl
      error 
        nodeDefinitionId
        message
      
      childProcessInstances 
        id
        processName
        businessKey
      
      nodes 
        id
        nodeId
        name
        enter
        exit
        type
        definitionId
      
    
  
`;

这是错误的堆栈跟踪:

   console.log
      ApolloError: Network error: No more mocked responses for the query: query getProcessInstanceById($id: String) 
        ProcessInstances(where: id: equal: $id) 
          id
          processId
          processName
          businessKey
          parentProcessInstanceId
          parentProcessInstance 
            id
            processName
            businessKey
          
          roles
          variables
          state
          start
          lastUpdate
          end
          addons
          endpoint
          addons
          serviceUrl
          error 
            nodeDefinitionId
            message
          
          childProcessInstances 
            id
            processName
            businessKey
          
          nodes 
            id
            nodeId
            name
            enter
            exit
            type
            definitionId
          
        
      
      , variables: 
          at new ApolloError (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:92:26)
          at ObservableQuery.getCurrentResult (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:218:20)
          at QueryData.getQueryResult (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:357:56)
          at QueryData._this.getExecuteResult (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:111:26)
          at QueryData.execute (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:160:47)
          at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:518:55
          at useDeepMemo (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:465:14)
          at useBaseQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:517:16)
          at Object.useQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:539:10)
          at Object.useGetProcessInstanceByIdQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/graphql/types.tsx:1253:27)
          at ProcessDetailsPage (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/ProcessDetailsPage.tsx:49:9)
          at renderWithHooks (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:15108:18)
          at updateFunctionComponent (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:16925:20)
          at beginWork$1 (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:18498:16)
          at beginWork$$1 (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:23193:14)
          at performUnitOfWork (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:22211:12)
          at workLoopSync (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:22185:22)
          at renderRoot (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21878:11)
          at runRootCallback (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21554:20)
          at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:11353:24
          at unstable_runWithPriority (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/scheduler/cjs/scheduler.development.js:643:12)
          at runWithPriority$2 (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:11305:10)
          at flushSyncCallbackQueueImpl (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:11349:7)
          at flushSyncCallbackQueue (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:11338:3)
          at scheduleUpdateOnFiber (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21431:9)
          at dispatchAction (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:15816:5) 
        graphQLErrors: [],
        networkError: Error: No more mocked responses for the query: query getProcessInstanceById($id: String) 
          ProcessInstances(where: id: equal: $id) 
            id
            processId
            processName
            businessKey
            parentProcessInstanceId
            parentProcessInstance 
              id
              processName
              businessKey
            
            roles
            variables
            state
            start
            lastUpdate
            end
            addons
            endpoint
            addons
            serviceUrl
            error 
              nodeDefinitionId
              message
            
            childProcessInstances 
              id
              processName
              businessKey
            
            nodes 
              id
              nodeId
              name
              enter
              exit
              type
              definitionId
            
          
        
        , variables: 
            at MockLink.request (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-testing/lib/react-testing.cjs.js:85:13)
            at execute (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-link/src/link.ts:131:10)
            at QueryManager.getObservableFromLink (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:2051:89)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:2106:32
            at new Promise (<anonymous>)
            at QueryManager.fetchRequest (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:2105:14)
            at QueryManager.<anonymous> (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:1466:38)
            at step (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/tslib/tslib.js:139:27)
            at Object.next (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/tslib/tslib.js:120:57)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/tslib/tslib.js:113:75
            at new Promise (<anonymous>)
            at __awaiter (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/tslib/tslib.js:109:16)
            at QueryManager.fetchQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:1404:35)
            at QueryManager.observeQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:1862:19)
            at ObservableQuery.setUpQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:507:20)
            at ObservableQuery.onSubscribe (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:471:14)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/apollo-client/bundle.umd.js:139:22
            at new Subscription (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/zen-observable/lib/Observable.js:197:34)
            at ObservableQuery.subscribe (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/zen-observable/lib/Observable.js:279:14)
            at QueryData.startQuerySubscription (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:305:52)
            at QueryData._this.getExecuteResult (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:113:13)
            at QueryData.execute (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:160:47)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:518:55
            at useDeepMemo (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:465:14)
            at useBaseQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:517:16)
            at Object.useQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:539:10)
            at Object.useGetProcessInstanceByIdQuery (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/graphql/types.tsx:1253:27)
            at ProcessDetailsPage (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/ProcessDetailsPage.tsx:49:9)
            at renderWithHooks (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:15108:18)
            at mountIndeterminateComponent (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:17342:13)
            at beginWork$1 (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:18486:16)
            at beginWork$$1 (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:23193:14)
            at performUnitOfWork (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:22211:12)
            at workLoopSync (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:22185:22)
            at renderRoot (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21878:11)
            at scheduleUpdateOnFiber (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21419:22)
            at scheduleRootUpdate (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:24319:3)
            at updateContainerAtExpirationTime (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:24347:10)
            at updateContainer (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:24436:10)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:24963:7
            at unbatchedUpdates (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21687:12)
            at legacyRenderSubtreeIntoContainer (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:24962:5)
            at Object.render (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:25042:12)
            at fn (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:437:26)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:354:37
            at batchedUpdates$1 (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom.development.js:21643:12)
            at act (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1002:14)
            at Object.act (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1418:12)
            at wrapAct (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:354:13)
            at Object.render (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:423:16)
            at new ReactWrapper (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/enzyme/src/ReactWrapper.js:115:16)
            at Object.mount (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/enzyme/src/mount.js:10:10)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/tests/ProcessDetailsPage.test.tsx:160:21
            at step (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/tests/ProcessDetailsPage.test.tsx:44:23)
            at Object.next (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/tests/ProcessDetailsPage.test.tsx:25:53)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/tests/ProcessDetailsPage.test.tsx:19:71
            at new Promise (<anonymous>)
            at Object.<anonymous>.__awaiter (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/tests/ProcessDetailsPage.test.tsx:15:12)
            at Object.<anonymous> (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/packages/management-console/src/components/Templates/ProcessDetailsPage/tests/ProcessDetailsPage.test.tsx:159:26)
            at Object.asyncJestTest (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:100:37)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/jest-jasmine2/build/queueRunner.js:45:12
            at new Promise (<anonymous>)
            at mapper (/home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/jest-jasmine2/build/queueRunner.js:28:19)
            at /home/ajaganat/Desktop/Kogito/kogito-apps/kogito-apps/node_modules/jest-jasmine2/build/queueRunner.js:75:41,
        message: 'Network error: No more mocked responses for the query: query getProcessInstanceById($id: String) \n' +
          '  ProcessInstances(where: id: equal: $id) \n' +
          '    id\n' +
          '    processId\n' +
          '    processName\n' +
          '    businessKey\n' +
          '    parentProcessInstanceId\n' +
          '    parentProcessInstance \n' +
          '      id\n' +
          '      processName\n' +
          '      businessKey\n' +
          '    \n' +
          '    roles\n' +
          '    variables\n' +
          '    state\n' +
          '    start\n' +
          '    lastUpdate\n' +
          '    end\n' +
          '    addons\n' +
          '    endpoint\n' +
          '    addons\n' +
          '    serviceUrl\n' +
          '    error \n' +
          '      nodeDefinitionId\n' +
          '      message\n' +
          '    \n' +
          '    childProcessInstances \n' +
          '      id\n' +
          '      processName\n' +
          '      businessKey\n' +
          '    \n' +
          '    nodes \n' +
          '      id\n' +
          '      nodeId\n' +
          '      name\n' +
          '      enter\n' +
          '      exit\n' +
          '      type\n' +
          '      definitionId\n' +
          '    \n' +
          '  \n' +
          '\n' +
          ', variables: ',
        extraInfo: undefined
      

      at ProcessDetailsPage (src/components/Templates/ProcessDetailsPage/ProcessDetailsPage.tsx:52:11)

谁能帮我找出哪里出错了?非常感谢。

【问题讨论】:

【参考方案1】:

模拟响应的变量需要与请求的值和结构完全匹配。在我看来,您缺少“平等”道具。 尝试像这样配置你的模拟:

const mocks = [
      
        request: 
          query: GetProcessInstanceByIdDocument,
          variables: 
            id:  equal: '201a8a42-043e-375a-9f52-57c804b24db4' ,
          ,
        ,
        result: 
          data: 
            someStuff: 'whatever',
          ,
        ,
      ,
    ]

【讨论】:

以上是关于在 jest-react 中使用 MockedProvider 会导致错误“查询没有更多的模拟响应”的主要内容,如果未能解决你的问题,请参考以下文章

reactjs / jest:无法使用 MockedProvider 用数据填充 react-apollo 组件?

在 Observable RxSwift 中使用 'asPromise()' 可以在 PromiseKit Promise 中使用吗?

可以在 SELECT 查询中使用 IF() 但不能在 UPDATE 中使用

如何在 Python 中使用 kivy 在 TabeedPanel 中使用 GridLayout

Vue3中使用Pinia

为啥不能在视图中使用它,因为它在控制器中使用?