next.js: with-jest example doesnt work

when i run test from npm scripts i have error

  C:\with-jest-app\jest.setup.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { configure } from 'enzyme';
                                                                                                    ^
    
    SyntaxError: Unexpected token {
      
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)
Tech Version
next 5.1.0
node 10.0.0

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 28 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Hello there! I added this following .babelrc

{
  "env": {
    "development": {
      "presets": ["next/babel"]
    },
    "production": {
      "presets": ["next/babel"]
    },
    "test": {
      "presets": ["env", "react"]
    }
  }
}

and installed yarn add --dev babel-jest babel-preset-env babel-preset-react

Worked for me.

and now seeing this error

    Plugin 0 specified in "/Users/mick/code/urban-signs/node_modules/next/babel.js" provided an invalid property of "default" (While processing preset: "/Users/mick/code/urban-signs/node_modules/next/babel.js")

      at Plugin.init (node_modules/babel-core/lib/transformation/plugin.js:131:13)
      at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
          at Array.map (<anonymous>)
      at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)

@binarykitchen I also got that error and fixed it by adding "babel-core": "7.0.0-bridge.0" to package.json as shown here: https://github.com/zeit/next.js/blob/905da6f92bd36b48c5067f1f1525004777213e17/examples/with-jest/package.json#L5

how would we enable babel to use es6 instead of es5?