Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jest testing with vite

Hi i’m newbie with vite and jest.
I’am facing a problem with my test code. In my App.test.jsx file test and expect is not defined

Package.json

{
  "name": "network-app",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
       "dev": "vite",
       "build": "vite build",
       "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
       "preview": "vite preview",
       "test": "jest"
  },
  "dependencies": {
       "react": "^18.2.0",
       "react-dom": "^18.2.0"
  },
  "devDependencies": {
       "@testing-library/jest-dom": "^5.16.5",
       "@testing-library/react": "^14.0.0",
       "@testing-library/user-event": "^14.4.3",
       "@types/jest": "^29.5.1",
       "@types/react": "^18.0.28",
       "@types/react-dom": "^18.0.11",
       "@vitejs/plugin-react": "^4.0.0",
       "eslint": "^8.38.0",
       "eslint-plugin-react": "^7.32.2",
       "eslint-plugin-react-hooks": "^4.6.0",
       "eslint-plugin-react-refresh": "^0.3.4",
       "jest": "^29.5.0",
       "vite": "^4.3.2"
 }

App.test.jsx

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 test('Renders main page correctly', () => {
     expect(true).toBeTruthy();
 });

Any idea how to solve this issue?

>Solution :

In jest’s installation guide, it’s indicated that vite doesn’t support jest due to it’s different plugin system. There’s a library known as vite-jest which can be installed and configured easily.

The Jest documentation can be helpful in this case:
Jest Installation in Vite

Here’s the link to the Vite-Jest library: Vite-Jest NPM Library

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading