Nikos
Nikos

Reputation: 7551

Errors when porting Testing Library React tests from Create react App to Vitest

I'm having issues moving react testing lib tests from create react app to vite:

src/Pages/WelcomePage/views/SelectUser/index.test.jsx [ src/Pages/WelcomePage/views/SelectUser/index.test.jsx ]
Error: Cannot find module 'react-dom/client'
Require stack:
- /Users/nikos/WebstormPro.../node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@testing-library/react/dist/pure.js
 ❯ Object.<anonymous> node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@testing-library/react/dist/pure.js:35:46

Current libs in white

enter image description here

edit -------------- upgrading to

  "react": "^18.1.0",
    "react-dom": "^18.1.0",

fixed the above but now I get:

 ❯ resetClipboardStubOnView node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@testing-library/user-event/dist/index.mjs:320:30
    318| }
    319| function resetClipboardStubOnView(window) {
    320|   if (isClipboardStub(window.navigator.clipboard)) {
       |                              ^

Upvotes: 2

Views: 1080

Answers (1)

Nikos
Nikos

Reputation: 7551

Missing the following in the vite config

  test: {
    globals: true,
    environment: "happy-dom", // or 'jsdom', 'node'

  },

If you get error Error: Cannot find module 'react-dom/client'

Upgrade to React 18 and tell your clients you are dumping ie11.

Upvotes: 1

Related Questions