As part of my course, I need to build a web app from scratch using React and Redux.
I've spent a few days now trying to set everything up, while trying to configure all the setting necessary to test the application with Jest and Enzyme.
However, everything I have tried has resulted in some form of error message that has prevented the tests from running.
I honestly have no idea what I've done wrong, but its seems like a complete mess.
Does anyone know why the error message for my test is flagging the React import? SyntaxError: Cannot use import statement outside a module
Here is my package.json file:
{"type": "module",
"name": "reddit-client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@reduxjs/toolkit": "^1.5.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"babel-jest": "^26.6.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-redux": "^7.2.3",
"react-scripts": "^1.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject",
"test:watch": "npm test -- --watch"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"transform": {
"\\.js$": "<rootDir>/node_modules/babel-jest"
},
"devDependencies": {
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.2",
"enzyme": "^3.11.0",
"jest": "^26.6.0",
"jest-enzyme": "^7.1.2"
}
}
Along with my .babelrc file:
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"transformIgnorePatterns": [
"node_modules/(?!(babel-jest)/)"
]
}
And the test itself, which doesn't have any code to it. But as far as I'm aware that shouldn't matter at this point?:
import React from 'react';
import Header from './Header.js';
import {shallow } from 'enzyme';
it('should render without errors', () => {
});
Any advice you can give me get this up and running would be massively appreciated!