I'm trying to make a simple unit test with a React component but I keep getting:
C:\work\portfolio\node_modules\gsap\TweenMax.js:13
import TweenLite, { TweenPlugin, Ease, Power0, Power1, Power2, Power3, Power4, Linear } from "./TweenLite.js";
^^^^^^^^^
Which is an error with an import of one of children's of 'App' components 3rd party libraries.
import React from "react";
import { shallow } from 'enzyme';
import App from "./App";
fit("renders without crashing", () => {
const wrapper = shallow(<App />);
});
app.js
import React from "react";
import "./App.css";
import ChronologyGraph from "./chronology/ChronologyGraph";
import { nodeTypes, milestones } from "../staticData";
const App = () => (
<ChronologyGraph
width="700"
height="800"
nodeSize={10}
milestones={milestones.reverse()}
columns={nodeTypes}
/>
);
export default App;
package.json:
{
"name": "portfolio",
"version": "0.1.0",
"private": true,
"dependencies": {
"font-awesome": "^4.7.0",
"gsap": "^2.0.1",
"moment": "^2.22.2",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-fontawesome": "^1.6.1",
"react-scripts": "^1.1.5",
"react-transition-group": "^2.4.0",
"typeface-lato": "0.0.54",
"typeface-roboto": "0.0.54",
"uuid": "^3.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"lint": "eslint src",
"test": "react-scripts test --env=jsdom",
"testCov": "react-scripts test --env=jsdom --coverage",
"eject": "react-scripts eject"
},
"devDependencies": {
"enzyme": "^3.4.4",
"enzyme-adapter-react-16": "^1.2.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.9.1",
"prettier-eslint": "^8.8.2"
}
}
I couldn't find any similar examples online, am I supposed to somehow mock the import of a child? I thought 'shallow' render wouldn't import children and thus children's imports
(enzyme maintainer here)
Third party modules should be transpiled prepublish - since it's not safe to run babel on node_modules, and since node doesn't support import
. You have basically these options:
gsap
so they properly transpile prepublishgsap
with something else