title: Error no Jest: This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript
body: <p>I'm trying to run Jest with React, I started the project with --create-react-app, then added --babel and after --jest, but when I run [yarn jest], this error is displayed on screen, can anyone help me?</p>
  
  <p>This is the error:</p>
  
  <pre><code> FAIL  src/pages/users/__tests__/add.test.js
   Test suite failed to run
  
  Jest encountered an unexpected token
  
  This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
  
  By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
  
  Here's what you can do:
   • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
   • If you need a custom transformation specify a "transform" 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 "moduleNameMapper" config option.
  
  You'll find more details and examples of these config options in the docs:
  https://jestjs.io/docs/en/configuration.html
  
  Details:
  
  SyntaxError: /usr/lib/myProjects/tryning/src/pages/users/add/index.js: Unexpected token (124:8)
  
    122 | 
    123 |     return (
  &gt; 124 |         &lt;&gt;
        |         ^
    125 |             &lt;Top /&gt;
    126 |             &lt;Menu /&gt;
    127 |             &lt;div className="user-add-form"&gt;
  
    at Parser.raise (node_modules/@babel/parser/src/parser/location.js:41:63)
    at Parser.unexpected (node_modules/@babel/parser/src/parser/util.js:160:16)
    at Parser.parseExprAtom (node_modules/@babel/parser/src/parser/expression.js:1143:20)
    at Parser.parseExprSubscripts (node_modules/@babel/parser/src/parser/expression.js:553:23)
    at Parser.parseMaybeUnary (node_modules/@babel/parser/src/parser/expression.js:533:21)
    at Parser.parseExprOps (node_modules/@babel/parser/src/parser/expression.js:301:23)
    at Parser.parseMaybeConditional (node_modules/@babel/parser/src/parser/expression.js:256:23)
    at Parser.parseMaybeAssign (node_modules/@babel/parser/src/parser/expression.js:186:21)
    at Parser.parseParenAndDistinguishExpression (node_modules/@babel/parser/src/parser/expression.js:1312:16)
    at Parser.parseExprAtom (node_modules/@babel/parser/src/parser/expression.js:1050:21)
  
    Test Suites: 1 failed, 1 total
    Tests:       0 total
    Snapshots:   0 total
    Time:        4.267s
    Ran all test suites.
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  </code></pre>
  
  <p>This is file test:</p>
  
  <pre><code>import React from 'react';
  
  import Enzyme, { mount } from 'enzyme';
  import Adapter from 'enzyme-adapter-react-16';
  Enzyme.configure({ adapter: new Adapter() });
  const addUser = require('../add/index');
  
  describe('MyComponent', () =&gt; {
      it('works', () =&gt; {
          expect(addUser.fieldCheck('Nelson')).to(true);
      });
  });  
  </code></pre>
  
  <p>This is the file I am trying to test:</p>
  
  <pre><code>      import React, { useState } from 'react';
        import './style.css';
        import Menu from '../../../components/menu';
        import Top from '../../../components/top';
        import { Link } from 'react-router-dom';
  
      const AddUser = () =&gt; {
  
      const [nameInput, setName] = useState('');
      const [cpfInput, setCpf] = useState('');
      const [userInput, setUser] = useState('');
      const [passInput, setPass] = useState('');
  
      let accounts = [];
  
      var accountsJson = JSON.parse(localStorage.getItem('tableUser'));
  
      const fieldCheck = field =&gt; {
          if (field.value === null || field.value.trim() === ""){
              field.style = "border: 1px solid #ff0000";
              return false;
          }
          else{
              field.style = "border: 1px solid #339680";
              return true;
          }
      }
  
      const account = {
          name: '',
          cpf: '',
          user: '',
          pass: '',
      };
  
      const finalWarning = (operation, error) =&gt; {
          switch (operation) {
              case 'save':
                  return 'Save with sucess!';
              case 'error':
                  return 'An error has occurred: '
                      .concat(error)
                      .concat("!");
              case 'cancel':
                  return 'The action has been undone!';
              case 'empty':
                  return 'Fields on red not can are empty!'
  
              default:
                  return 'Do not possible return in [finalWarning] &gt;52';
          }
      }
  
      const confirmSave = () =&gt; {
          var op = window.confirm("Are you sure you want to save?");
          return op;
      }
  
      const cleanFields = () =&gt; {
          setName('');
          setCpf('');
          setUser('');
          setPass('');
      }
  
      const emptyFields = inputsElements =&gt; {
          var haveEmpty = false;
          inputsElements.map(input =&gt; {
              if (document.getElementsByName(input)[0].value === "") {
                  document.getElementsByName(input)[0].style = "border: 1px solid #ff0000";
                  haveEmpty = true;
              }
              else {
                  haveEmpty = false;
              }
          });
          if (haveEmpty) {
              alert(finalWarning('empty'));
              return true;
          }
          else {
              return false;
          }
      }
  
      const addAccount = account =&gt; {
          accounts.push(account);
          localStorage.setItem('tableUser', JSON.stringify(accounts));
      }
  
      const handleFormSubmit = event =&gt; {
          event.preventDefault();
  
          account.name = nameInput;
          account.cpf = cpfInput;
          account.user = userInput;
          account.pass = passInput;
  
          if (!emptyFields(['nameInput', 'cpfInput', 'userInput', 'passInput'])) {
              if (confirmSave())
                  try {
                      accounts = [];
                      for (var i in accountsJson)
                          accounts.push(accountsJson[i]);
  
                      addAccount(account);
  
                      cleanFields();
  
                      alert(finalWarning('save'));
                      window.location.href = "/users";
                  }
                  catch (e) {
                      alert(finalWarning('error', e));
                      alert(e);
                      window.location.href = "/users";
                  }
              else
                  alert(finalWarning('cancel'));
          }
      }
  
      return (
          &lt;&gt;
              &lt;Top /&gt;
              &lt;Menu /&gt;
              &lt;div className="user-add-form"&gt;
                  &lt;div className="line-top"&gt;&lt;/div&gt;
                  &lt;form method="post" id="user-add-form" onSubmit={handleFormSubmit}&gt;
                      &lt;div className="user-add-fields"&gt;
                          Name
                      &lt;input
                              onChange={e =&gt; setName(e.target.value)}
                              name="nameInput"
                              value={nameInput}
                              type="text"
                              placeholder="Insert name."
                              onBlur={e =&gt; fieldCheck(e.target)}
                          /&gt;
                          CPF
                      &lt;input
                              onChange={e =&gt; setCpf(e.target.value)}
                              name="cpfInput"
                              value={cpfInput}
                              type="text"
                              placeholder="Insert cpf."
                              onBlur={e =&gt; fieldCheck(e.target)}
                          /&gt;
                          User
                      &lt;input
                              onChange={e =&gt; setUser(e.target.value)}
                              name="userInput"
                              value={userInput}
                              type="text"
                              placeholder="Insert user."
                              onBlur={e =&gt; fieldCheck(e.target)}
  
                          /&gt;
                          Password
                      &lt;input
                              onChange={e =&gt; setPass(e.target.value)}
                              name="passInput"
                              value={passInput}
                              type="password"
                              placeholder="Insert password."
                              onBlur={e =&gt; fieldCheck(e.target)}
                          /&gt;
                      &lt;/div&gt;
                      &lt;button
                          type="submit"
                          className=" button user-add-save-button"
                      &gt;
                          Save
                      &lt;/button&gt;
                  &lt;/form&gt;
                  &lt;Link to="/Users" className="button user-add-cancel-button" &gt;
                      Cancel
                  &lt;/Link&gt;
              &lt;/div &gt;
          &lt;/&gt;
      );
  }
  
  export default AddUser;
  </code></pre>
  
  <p>This is my file package.json:</p>
  
  <pre><code>{
    "name": "trying",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
      "@testing-library/react": "^9.3.3",
      "babel": "^6.23.0",
      "enzyme": "^3.10.0",
      "enzyme-adapter-react-16": "^1.15.1",
      "jest": "^24.9.0",
      "react": "^16.12.0",
      "react-dom": "^16.12.0",
      "react-router-dom": "^5.1.2",
      "react-scripts": "3.2.0",
      "tab": "^1.0.0",
      "tabs": "^0.2.0",
      "webfontloader": "^1.6.28"
    },
    "scripts": {
      "start": "react-scripts start",
      "build": "react-scripts build",
      "test": "jest",
      "eject": "react-scripts eject"
    },
    "eslintConfig": {
      "extends": "react-app"
    },
    "browserslist": {
      "production": [
        "&gt;0.2%",
        "not dead",
        "not op_mini all"
      ],
      "development": [
        "last 1 chrome version",
        "last 1 firefox version",
        "last 1 safari version"
      ]
    }
  }
  </code></pre>
  
  <p>This is my Babel.js:</p>
  
  <pre><code>{
      "presets": ["@babel/preset-env"],
      "plugins": [
          "@babel/plugin-proposal-object-rest-spread",
          "@babel/plugin-transform-async-to-generator"
      ]
  } 
  </code></pre>
  
  <p>Follow the project link on Github to:
  <a href="https://github.com/nelsonanjos/userRegistration" rel="nofollow noreferrer">User Registration Github</a></p>