Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo react import not transpiled when running jest tests #5516

Closed
SLedunois opened this issue Feb 10, 2018 · 2 comments
Closed

Apollo react import not transpiled when running jest tests #5516

SLedunois opened this issue Feb 10, 2018 · 2 comments

Comments

@SLedunois
Copy link

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 #3202 but it seems that the solution doesn't work with my project.

Can you help me?

Thank you,

SLedunois

@cpojer
Copy link
Member

cpojer commented Feb 10, 2018

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)

@cpojer cpojer closed this as completed Feb 10, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants