Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Apollo react import not transpiled when running jest tests #1663

@SLedunois

Description

@SLedunois

Hi guys.

I'm currently experimenting an issue with my new React project using React and GraphQL Apollo. Here is my stack :

  • Webpack to build/dev to project
  • Babel to transpile javascript/jsx files
  • Jest to run tests
  • Enzyme to test my react components

The issue: When I run my tests, it seems that Apollo react client is not transpiled and throw tests :

pp/containers/App/__tests__/App.test.jsx
  ● Test suite failed to run

    /Users/utilisateur/Project/TrAVis/TrAVis/node_modules/react-apollo/graphql.js:19
    import { Component, createElement } from 'react';
    ^^^^^^

    SyntaxError: Unexpected token import

      1 | import React, { Component } from 'react';
    > 2 | import graphql from 'react-apollo/graphql';
      3 | import { bool, object, shape } from 'prop-types';
      4 |
      5 | import getUserQuery from './query';

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:318:17)
      at Object.<anonymous> (app/containers/App/App.jsx:2:16)
      at Object.<anonymous> (app/containers/App/__tests__/App.test.jsx:4:12)

My jest configuration is :

module.exports = {
  verbose: true,
  moduleNameMapper: {
    '\\.(css)$': 'identity-obj-proxy',
  },
  transform: {
    '^.+\\.(js|jsx)$': 'babel-jest'
  }
};

and my .babelrc is simply :

{
  "presets": [
    "react", 
    "es2015"
  ]
}

I found this issue jestjs/jest#3202 but it seems that the solution doesn't work with my project.

Can you help me?

Thank you,

SLedunois

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions