Skip to content

Remove @testing-library/react-hooks as a peer dependency #8739

Closed

Description

@Dosant

I tried to remove @testing-library/react-hooks from Kibana since we're no longer using it elastic/kibana#222350. This was replaced by renderHook from @testing-library/react.

But Kibana PR failed since it turned out that eui is using it as a peer dependecy, so @testing-library/react-hooks isn't installed with eui package.

Example error:

<head></head>
FAIL  src/platform/plugins/shared/share/public/components/export_popover/export_popover.test.tsx
--
  | ● Test suite failed to run
  |  
  | Cannot find module '@testing-library/react-hooks/dom' from 'node_modules/@elastic/eui/test-env/test/rtl/render_hook.js'
  |  
  | Require stack:
  | node_modules/@elastic/eui/test-env/test/rtl/render_hook.js
  | node_modules/@elastic/eui/test-env/test/rtl/index.js
  | src/platform/plugins/shared/share/public/components/export_popover/export_popover.test.tsx
  |  
  | 14 \| import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
  | 15 \| import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks';
  | > 16 \| import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
  | \| ^
  | 17 \| import { toastsServiceMock } from '@kbn/core-notifications-browser-mocks/src/toasts_service.mock';
  | 18 \| import { ExportMenu } from './export_popover';
  | 19 \| import type { IShareContext } from '../context';
  |  
  | at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
  | at Object.<anonymous> (node_modules/@elastic/eui/test-env/test/rtl/render_hook.js:23:37)
  | at Object.<anonymous> (node_modules/@elastic/eui/test-env/test/rtl/index.js:85:20)
  | at Object.require (src/platform/plugins/shared/share/public/components/export_popover/export_popover.test.tsx:16:1)

I suggest EUI gets rid of this dependency in favor of renderHook from @testing-library/react as a peer dependency

Activity

  1. Dosant commented on Jun 4, 2025

    @Dosant
    ContributorAuthor

    Looking at the code,

    if (process.env.REACT_VERSION === '18') {
    renderHook = require('@testing-library/react').renderHook;
    renderHookAct = require('@testing-library/react').act;
    } else {
    renderHook = require('@testing-library/react-hooks/dom').renderHook;
    renderHookAct = require('@testing-library/react-hooks/dom').act;
    }

    It looks like Kibana is falling back to a non-React 18 version because we haven't defined the EUI specific process variable for kibana test env. Maybe EUI can figure it out from the React package version?

  2. tkajtoch commented on Jun 5, 2025

    @tkajtoch
    Contributor

    Hi @Dosant let me look into this and get back to you.

  3. self-assigned this
    on Jun 5, 2025
  4. added
    ⚠️ needs validation
    on Jun 5, 2025
  5. tkajtoch commented on Jun 12, 2025

    @tkajtoch
    Contributor

    We actually only use @testing-library/react-hooks as a devDependency, which makes this whole thing a bit confusing. Long story short, since this hook contains internal logic, it should likely be treated as internal-only. We don't export it directly, and all usages in Kibana import it from the "hidden" @elastic/eui/lib/test/rtl/render_hook file directly.

    I believe this should be fixed by our test utils library that I worked on earlier this year. Let me circle back to this and see if we could quickly release it and replace Kibana usages to fix the issue you're seeing!

  6. removed
    ⚠️ needs validation
    on Jun 12, 2025
  7. github-actions commented on Dec 9, 2025

    @github-actions

    👋 Hi there - this issue hasn't had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it's unlikely that we'll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it's stale for over a year), the issue will be auto-closed.

  8. added
    stale-issue
    on Dec 9, 2025
  9. added theissue type on Dec 15, 2025
  10. removed
    stale-issue
    on Dec 16, 2025
  11. github-actions commented on Jun 14, 2026

    @github-actions

    👋 Hi there - this issue hasn't had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it's unlikely that we'll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it's stale for over a year), the issue will be auto-closed.

  12. added
    stale-issue
    on Jun 14, 2026
  13. removed
    stale-issue
    on Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions