Cannot find module '@testing-library/dom' from 'node_modules/@testing-library/user-event/dist/click.js' Require stack:
Asked Answered
J

1

8

In a project we recently started using userEvent instead of fireEvent but now we are getting this issue

FAIL src/modules/DashboardHeader/index.test.tsx     

      ● Test suite failed to run  

        Cannot find module '@testing-library/dom' from 'node_modules/@testing-library/user-event/dist/click.js'  

        Require stack:  

          node_modules/@testing-library/user-event/dist/click.js  

          node_modules/@testing-library/user-event/dist/index.js  

          src/modules/DashboardHeader/index.test.tsx  

           5 | 
           6 | 
        >  7 | import userEvent from '@testing-library/user-event';  
Jarrad answered 8/5, 2023 at 17:5 Comment(0)
J
13

As per the documentation https://testing-library.com/docs/ecosystem-user-event/

in order to use userEvent, we need not just "@testing-library/user-event" but also @testing-library/dom.

npm install --save-dev @testing-library/user-event @testing-library/dom 

So when I checked there was no entry for @testing-library/dom . After installing it, it started working.

Jarrad answered 8/5, 2023 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.