0

我正在尝试使用 Nivo 和 Rect (Typescript) 实现一些单元测试。为此,我正在使用@testing-library/react。

当我使用此代码执行测试时,考虑到“ResponsiveChart”的实现位于“MyPage”组件内部,它会返回一个奇怪的错误响应。

const wrapper = customRender(
      <BrowserRouter basename="/">
        <PageProvider>
          <FiltersSectionProvider>
            <MyPage />
          </FiltersSectionProvider>
        </PageProvider>
      </BrowserRouter>,
      mocks
    );

错误:

 console.error
      Error: Uncaught [TypeError: o.disconnect is not a function]
          at reportException (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
          at innerInvokeEventListeners (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:341:9)
          at invokeEventListeners (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
          at HTMLUnknownElementImpl._dispatch (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
          at HTMLUnknownElementImpl.dispatchEvent (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
          at HTMLUnknownElement.dispatchEvent (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
          at Object.invokeGuardedCallbackDev (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
          at invokeGuardedCallback (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
          at flushPassiveEffectsImpl (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:23543:11)
          at unstable_runWithPriority (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/scheduler/cjs/scheduler.development.js:468:12) TypeError: o.disconnect is not a function
          at /Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/@nivo/core/src/hooks/usePartialTheme.js:5:68
          at HTMLUnknownElement.callCallback (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:3945:14)
          at HTMLUnknownElement.callTheUserObjectsOperation (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
          at innerInvokeEventListeners (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
          at invokeEventListeners (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
          at HTMLUnknownElementImpl._dispatch (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
          at HTMLUnknownElementImpl.dispatchEvent (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
          at HTMLUnknownElement.dispatchEvent (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
          at Object.invokeGuardedCallbackDev (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
          at invokeGuardedCallback (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
          at flushPassiveEffectsImpl (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:23543:11)
          at unstable_runWithPriority (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/scheduler/cjs/scheduler.development.js:468:12)
          at runWithPriority$1 (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
          at flushPassiveEffects (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:23447:14)
          at performSyncWorkOnRoot (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:22269:3)
          at /Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:11327:26
          at unstable_runWithPriority (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/scheduler/cjs/scheduler.development.js:468:12)
          at runWithPriority$1 (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:11276:10)
          at flushSyncCallbackQueueImpl (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:11322:9)
          at flushSyncCallbackQueue (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:11309:3)
          at batchedUpdates$1 (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom.development.js:22387:7)
          at act (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14)
          at cleanupAtContainer (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/@testing-library/react/dist/pure.js:143:26)
          at Set.forEach (<anonymous>)
          at cleanup (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/@testing-library/react/dist/pure.js:137:21)
          at Object.<anonymous> (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/@testing-library/react/dist/index.js:33:25)
          at Promise.then.completed (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/utils.js:276:28)
          at new Promise (<anonymous>)
          at callAsyncCircusFn (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/utils.js:216:10)
          at _callCircusHook (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/run.js:175:40)
          at _runTest (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/run.js:152:5)
          at _runTestsForDescribeBlock (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/run.js:63:9)
          at _runTestsForDescribeBlock (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/run.js:57:9)
          at run (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/run.js:25:3)
          at runAndTransformResultsToJestFormat (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:176:21)
          at jestAdapter (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:109:19)
          at runTestInternal (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-runner/build/runTest.js:380:16)
          at runTest (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-runner/build/runTest.js:472:34)
          at Object.worker (/Users/israel.saraiva/dev/shell/res-rpm-frontend/node_modules/jest-runner/build/testWorker.js:133:12)

重要的是说我也在使用“MockedProvider”。

你们知道如何解决这个问题吗?谢谢!

4

0 回答 0