3

I'm trying to run a basic "mount React component" test in Jest. The test is

test("Create App component", () => {
  const div = document.createElement("div");
  ReactDOM.render(<App />, div);
  ReactDOM.unmountComponentAtNode(div);
});

The test infrastructure was set up using create-react-app.

The App component has a child that uses react-vis components.

When I try to run the test, I get the following error

import _AbstractSeries from './plot/series/abstract-series';
        ^^^^^^^^^^^^^^^

    SyntaxError: Unexpected identifier

    2 | import PropTypes from "prop-types";
    3 | import { withStyles } from "@material-ui/core/styles";
    > 4 | import {
        | ^
    5 |   AreaSeries,
    6 |   Crosshair,
    7 |   CustomSVGSeries,

    at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
    at Object.<anonymous> (src/components/Charts/MyCustomChart.js:4:1)

Any advice on how to get this test working?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
dommer
  • 19,610
  • 14
  • 75
  • 137
  • it seems `babel-jest` is not installed or `babel` is not configured properly. – skyboyer Jan 16 '19 at 10:48
  • Problem is that it works if I don't have react-vis components, so not sure how to resolve it. – dommer Jan 17 '19 at 11:05
  • take a look into https://github.com/facebook/jest/issues/6229 maybe it gives you idea where to continue. Hard to say for sure it looks like some file is not transformed while it needs that. Confusing thing that case depends on specific dependency while I believe error happens for your own code rather dependency's one. – skyboyer Jan 17 '19 at 11:14

1 Answers1

0

After lots of searching and deferring, I found the solution.

I found a similarly failed pipeline to mine: https://git.fluidware.it/milanoscaloromana/fcub/-/jobs/731

Then I followed the steps to see how it was fixed: https://git.fluidware.it/milanoscaloromana/fcub/commit/ec52c35284fd32039f256c4492e562a6180e51cc

You need to import from react-vis and not react-vis/es. WebStorm auto imports from the /es package for some reason.

MayTheSchwartzBeWithYou
  • 1,181
  • 1
  • 16
  • 32