Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Support for the experimental syntax jsx isn't currently enabled #5

Open
ClydeDz opened this issue Jun 27, 2022 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@ClydeDz
Copy link
Owner

ClydeDz commented Jun 27, 2022

Please explain the issue and what was your expectation

I created this app using the create react app command with the TypeScript command. The test files should automatically work, but they didn't. This issue reminds me to add tests to the app once this issue is fixed.

The main issue is being tracked in the library here - facebook/create-react-app#11700

Please elaborate the steps to reproduce the issue

Add a sample test file with the contents below.

import { render } from "@testing-library/react";

test('test', ()=> {
    render(<div>test</div>);
    expect(1).toBe(1);
});

Running the test produces the following output in the console.

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 "node_modules" 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 "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/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    SyntaxError: F:\Code\tweet-to-image\src\App.test.tsx: Support for the experimental syntax 'jsx' isn't currently enabled (4:12):

      2 |
      3 | test('fefe', ()=> {
    > 4 |     render(<div>fefe</div>);
        |            ^
      5 |     expect(1).toBe(1);
      6 | });
      7 |

    Add @babel/preset-react (https://github.com/babel/babel/tree/main/packages/babel-preset-react) 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://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-jsx) to the 'plugins' section to enable parsing.

      at instantiate (node_modules/@babel/parser/src/parse-error/credentials.js:61:22)
      at toParseError (node_modules/@babel/parser/src/parse-error.js:58:12)
      at Parser.raise (node_modules/@babel/parser/src/tokenizer/index.js:1736:19)
      at Parser.expectOnePlugin (node_modules/@babel/parser/src/tokenizer/index.js:1800:18)
      at Parser.parseExprAtom (node_modules/@babel/parser/src/parser/expression.js:1239:16)
      at Parser.parseExprSubscripts (node_modules/@babel/parser/src/parser/expression.js:684:23)
      at Parser.parseUpdate (node_modules/@babel/parser/src/parser/expression.js:663:21)
      at Parser.parseMaybeUnary (node_modules/@babel/parser/src/parser/expression.js:632:23)
      at Parser.parseMaybeUnaryOrPrivate (node_modules/@babel/parser/src/parser/expression.js:384:14)
      at Parser.parseExprOps (node_modules/@babel/parser/src/parser/expression.js:394:23)

Browser information

N/A

@ClydeDz ClydeDz added the bug Something isn't working label Jun 27, 2022
@ClydeDz ClydeDz self-assigned this Jun 27, 2022
@NurgaliyevS
Copy link

Where is the answer?

@thesparkvision
Copy link

thesparkvision commented Dec 23, 2022

Facing the same issue as Author described.

Tried

  • changing versions
  • deleting node_modules and re-install
  • setting env in package.json
  • clearing cache and re-running tests
  • updating babel configuration
  • adding .babelrc file

Nothing seems to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants