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

How to use jest to test React component in Vite? #2720

Closed
marialovesbeans opened this issue Mar 27, 2021 · 1 comment
Closed

How to use jest to test React component in Vite? #2720

marialovesbeans opened this issue Mar 27, 2021 · 1 comment

Comments

@marialovesbeans
Copy link

marialovesbeans commented Mar 27, 2021

Hi, I'm trying to test React components.

Step 1) I've created a file App.test.jsx:

// App.test.jsx
import App from './App'

const app = <App/> // <----- syntax error here

test('first test', () => {
  expect(true).toBe(true)
})

Step 2) On command line, run jest

Result:
It errors on the <App/> word saying:
Support for the experimental syntax 'jsx' isn't currently enabled. 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.

On Vite documentation, I don't see anywhere stating how to use jest to test React component. Does anyone know? Thanks!

@patak-dev
Copy link
Member

Here is a post explaining how to do the setup, you need the JSX babel plugin, jest and Vite are independent here

https://pranshushah.tech/getting-started-with-react-using-vitejs

At one point, we'll get first-class integration #1955

Other options for testing if you would like to explore:

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants