score:2
Mocha probably can't read your TestComponent
because it contains syntax unfamiliar to it (the JSX). You'll need to specify a compiler for mocha as well as babel presets (assuming you're using Babel).
Assuming you already have babel-core
and babel-preset-react
installed for your project, make these changes in your package.json:
"scripts": {
"test": "mocha --compilers js:babel-register \"./src/**/*.spec.js\""
},
"babel": {
"presets": ["react"]
}
score:1
You should add the .jsx extension to your require call, as by default it won't recognize .jsx files as modules.
Rick is also right about the compiler but in this case the error is due to the synthax of require. Then if you fix the require you will see an error of unexpected token, which is the lack of compiler.
You should therefore correct both points.
Source: stackoverflow.com
Related Query
- Unable to import a React Component in my Mocha test
- Mocha test of React component which uses System.js to handle css import
- React unable to import component -- module not found
- React Native Test Error - Unable to find node on an unmounted component
- Test with Mocha and Enzyme a React component that uses React CSS Modules
- Mocha & Enzyme - How to test that React component has no children?
- Using Mocha to test props on a rendered SVG component in React
- Unable to test component that exists within React Router?
- React functional component test file unable to update state value and call its props function
- Unable to test react component with using some mocked functions
- How to mock a nested component import in react js and test using react testing library
- Unable to import base64 image into react component with webpack
- Unable to mock a dispatch function to use in test case in React to track click event been fired from the component
- Can you import a function from a react component into a test file?
- Mocha test failing for React component containing an image
- Unable to import react component to my app.js
- How to import a CSS file in a React Component
- How to import image (.svg, .png ) in a React Component
- How to test a react component that is dependent on useContext hook?
- Difference between import React and import { Component } syntax
- How to test style for a React component attribute with Enzyme
- Jest Enzyme test a React component that returns null in render method
- How to test a prop update on React component
- Figuring out how to mock the window size changing for a react component test
- React & Jest, how to test changing state and checking for another component
- Test a React Component function with Jest
- How to test a React component with RouteComponentProps?
- Unable to use Arrow functions inside React component class
- How to unit test React Component shouldComponentUpdate method
- How to test decorated React component with shallow rendering
More Query from same tag
- How can I map over all of the formData entires to upload to firebase?
- How to sync Redux state and url hash tag params
- Typescript baseUrl not working in React Typescript project
- How should I handle internationalisation in a React library of components?
- Click a button to play sound on React.js
- How to get a function inside a script tag in react JS?
- How to add ::-webkit-scrollbar pseudo element in Chakra UI element? (React)
- create react app - npm run build issues
- Test connected component in React/Redux
- Data coming in Service Response but showing 'undefined' from where it is called - JavaScript | React
- Nested drawer/layout in react toolbox
- React Typescript onSubmit type
- Refactoring validation handling and messaging
- redux-saga when to use fork?
- How to request anonymously via Axios?
- How to put React component inside HTML string?
- Create a Comment Widget in React
- Format string from database into a url link with react, react-router, react-bootstrap-table
- Hide header on Login page
- Webpack-dev-server not bundling even after showing bundle valid message
- How to write an abstract class for a component (with extendable state & props)?
- Aborted request using AbortController in React Redux app is aborted forever
- Failed prop type: The prop `message` is marked as required in `Description`, but its value is `undefined`
- React Transition Group - Magnetic slider (change direction not working correctly)
- How to make a function to calculate the date and month of the year automatically
- Error while running ‘hello-react’ program in react.js
- Loop through components and return in switch case (React.js)
- Why my class method works in React without explicitly binding it to 'this'?
- useForm how to setValue for dynamic input
- Is it ok to change directly the state if we don't want to re-render?