score:3
you configured babel in your webpack config and this will only apply to webpack. when other tools, like jest, use babel, they won't see that configuration because they don't look at the webpack config. you can use a .babelrc
file to configure babel and that will apply to anything that runs babel (not just webpack).
using a .babelrc
is usually preferred as you want to have a general babel config, and if you need to override a setting, you can still do that in the specific application like in the webpack config.
create the following .babelrc
:
{
"presets": ["es2015", "react"]
}
with that, you can remove the presets
option in your webpack config because it will use the .babelrc
. note that the cachedirectory
option is specific to babel-loader
and is not used to configure the underlying babel.
you also have a typo in your test, tomatchsnapshot()
should be tomatchsnapshot()
.
expect(rendered.tojson()).tomatchsnapshot();
Source: stackoverflow.com
Related Query
- Unexpected Token - Jest for existing React + Web-pack app
- AWS - Get user token from an existing Cognito User Pool with username and password on an existing React web app
- React JS Jest causing "SyntaxError: Unexpected token ."
- Jest tests on React components: Unexpected token "<"
- react & web pack hot loader. "waiting for roots to load...to reload the inspector"
- React Jest test fails to run with ts-jest - Unexpected token on imported file
- Jest with Create React App: Test suite failed to run - Unexpected token
- React Jest test fails to run with ts-jest - Encountered an unexpected token on imported file
- React app hosted on s3 unexpected token <
- Error when running jest on a react native + typescript app (Jest encountered an unexpected token)
- How to use Turborepo for an existing react app created with Create React App in order to make it a monorepo?
- React Native: Transform Error for Unexpected Token (
- Jest encountered an unexpected token when working with React TypeScript
- React Jest - Unexpected token import
- Jest Error Unexpected token on react component
- Babel 7 Unexpected token for React component
- setup localStorage for testing React app with jest
- React testing with Jest and Enzyme (in Symfony) got "Syntax Error: Unexpected token import"
- Jest encountered an unexpected token with react + konva and/or react-konva
- Testing react components: Jest encountered an unexpected token
- React app: Jest encountered an unexpected token
- Test suits failed with "SyntaxError: Unexpected token 'export" ' react typescript using jest
- ' Jest encountered an unexpected token { ' error on react application
- How to generate bundle.js for existing react app created using `create-react-app CLI`
- Create React App SyntaxError: Unexpected Token
- While compiling my react app I am getting Module build failed: SyntaxError: Unexpected token
- SyntaxError: Invalid or unexpected token when testing react application with babel and jest
- Jest gives an error: "SyntaxError: Unexpected token export" for node_modules\@microsoft\mgt-react
- Issue with web pack when trying to create React App
- Unexpected token i in JSON at position 6 - react redux app
More Query from same tag
- Filtering multiple types of content in graphql
- cypress input field wont get cleared
- React 17.0.1 Form onChange skips the last number
- Drag and drop in reactjs not working
- React "export default" stateless component issue
- Reactjs - writing a function to enable a button on validation of input text
- Need to make Object value optional using JavaScript
- Tooltip on disabled Tab - Material Ui, React
- Why a value initialized in the onClick of a button result undefined?
- onSubmit() is not working in React.js
- Return number of "false" Boolean values from an array - MobX & React
- I overridden React.createElement, but jsx's button doesn't seem to call React.createElement
- React.memo performance is worse than with React.PureComponent
- Where does Heroku create the build folder? (getting 404 status error)
- Module not found: Can't resolve 'react'
- Tailwind CSS, positioning one image over another
- I can't import React components with webpack
- VM892:1 Uncaught SyntaxError: Unexpected token e in JSON at position 0
- How to write to Hasura from Gatsby?
- Insert custom React component into a String variable with html content
- Is it possible to declare a dynamic interface?
- Change select value in react.js
- How do I call setState from another Component in ReactJs
- Can't handlechange in Formik in Reach.Js
- React Js: Only change the class of the table cell that has been clicked
- How do I display my icon on the far left of the box component in ReactJs
- Nextjs build failing because of jsonwebtoken in _middleware.ts
- React functional component - How to access children method from Parent
- How to pass FlowRouter context in testing React components
- Calling action from another action