title: Vite / Jest / React-Testing
body: <p>I am trying to test in React application with Jest; my application uses Vite as a module bundler. The issue is, every time I run tests I get the following error:</p>
  <pre><code>   &gt; react-test@0.0.0 test
  &gt; jest
  
   FAIL  src/test/App.test.jsx
    ● Test suite failed to run
  
      Jest encountered an unexpected token
  
      Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
  
      Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
  
      By default &quot;node_modules&quot; folder is ignored by transformers.
  
      Here's what you can do:
       • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to 
  enable it.
       • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript      
       • To have some of your &quot;node_modules&quot; files transformed, you can specify a custom &quot;transformIgnorePatterns&quot; in your config.
       • If you need a custom transformation specify a &quot;transform&quot; option in your config.
       • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the &quot;moduleNameMapper&quot; config option.
  
      You'll find more details and examples of these config options in the docs:
      https://jestjs.io/docs/configuration
      For information about custom transformations, see:
      https://jestjs.io/docs/code-transformation
  
      Details:
  
      SyntaxError: C:\Users\Tomas\Desktop\react-test\src\test\App.test.jsx: Support for the experimental syntax 'jsx' isn't currently enabled (8:30):
  
         6 |
         7 | test(&quot;renders content&quot;, ()=&gt;{
      &gt;  8 |     const component = render(&lt;App&gt;&lt;/App&gt;)
           |                              ^
         9 |     console.log(component)
        10 | })
  
      Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
      If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing.
  
        at Parser._raise (node_modules/@babel/parser/src/parser/error.js:150:45)
        at Parser.raiseWithData (node_modules/@babel/parser/src/parser/error.js:145:17)
        at Parser.expectOnePlugin (node_modules/@babel/parser/src/parser/util.js:214:18)
        at Parser.parseExprAtom (node_modules/@babel/parser/src/parser/expression.js:1238:16)
        at Parser.parseExprSubscripts (node_modules/@babel/parser/src/parser/expression.js:682:23)
        at Parser.parseUpdate (node_modules/@babel/parser/src/parser/expression.js:662:21)
        at Parser.parseMaybeUnary (node_modules/@babel/parser/src/parser/expression.js:633:23)
        at Parser.parseMaybeUnaryOrPrivate (node_modules/@babel/parser/src/parser/expression.js:388:14)        
        at Parser.parseExprOps (node_modules/@babel/parser/src/parser/expression.js:398:23)
        at Parser.parseMaybeConditional (node_modules/@babel/parser/src/parser/expression.js:356:23)
  
  Test Suites: 1 failed, 1 total
  Tests:       0 total
  Snapshots:   0 total
  Time:        1.379 s
  Ran all test suites.
  </code></pre>
  <p>Package.json</p>
  <pre><code>{
    &quot;name&quot;: &quot;react-test&quot;,
    &quot;private&quot;: true,
    &quot;version&quot;: &quot;0.0.0&quot;,
    &quot;type&quot;: &quot;module&quot;,
    &quot;scripts&quot;: {
      &quot;dev&quot;: &quot;vite&quot;,
      &quot;build&quot;: &quot;vite build&quot;,
      &quot;preview&quot;: &quot;vite preview&quot;,
      &quot;test&quot;: &quot;jest&quot;
    },
    &quot;dependencies&quot;: {
      &quot;react&quot;: &quot;^17.0.2&quot;,
      &quot;react-dom&quot;: &quot;^17.0.2&quot;
    },
    &quot;jest&quot;: {
      &quot;verbose&quot;: true,
      &quot;testEnvironment&quot;: &quot;jsdom&quot;,
      &quot;transform&quot;: {
        &quot;^.+\\.(js|jsx)$&quot;: &quot;babel-jest&quot;
      },
      &quot;moduleFileExtensions&quot;: [
        &quot;js&quot;,
        &quot;jsx&quot;
      ],
      &quot;moduleNameMapper&quot;: {
        &quot;\\.(gif|ttf|eot|svg|png)$&quot;: &quot;&lt;rootDir&gt;/test/__mocks__/fileMock.js&quot;,
        &quot;\\.(css|less|sass|scss)$&quot;: &quot;identity-obj-proxy&quot;
      }
    },
    &quot;devDependencies&quot;: {
      &quot;@babel/plugin-syntax-jsx&quot;: &quot;^7.16.7&quot;,
      &quot;@testing-library/jest-dom&quot;: &quot;^5.16.2&quot;,
      &quot;@testing-library/react&quot;: &quot;^12.1.3&quot;,
      &quot;@types/jest&quot;: &quot;^27.4.1&quot;,
      &quot;@vitejs/plugin-react&quot;: &quot;^1.0.7&quot;,
      &quot;jest&quot;: &quot;^27.5.1&quot;,
      &quot;vite&quot;: &quot;^2.8.0&quot;
    }
  }
  </code></pre>
  <p>App.test.jsx</p>
  <pre><code>import React from &quot;react&quot;;
  import &quot;@testing-library/jest-dom/extend-expect&quot;
  import { render } from &quot;@testing-library/react&quot;;
  import App from &quot;../App.jsx&quot;;
  
  
  test(&quot;renders content&quot;, ()=&gt;{
      const component = render(&lt;App&gt;&lt;/App&gt;)
      console.log(component)
  })
  </code></pre>