意外令牌,预期为“ {”

时间:2019-03-01 22:51:31

标签: typescript jestjs babel-jest

我正在尝试设置玩笑来测试我的反应代码。 但我在以下行的

android.intent.action.MY_PACKAGE_REPLACED

这是我的.babelrc文件

class app extends Component <State> {
迫切需要帮助。 更清楚地说,这是我的fake.spec.js。在导入语句中,我面临意外的令牌导入。

{
"presets": [
    "@babel/preset-env",
    "@babel/preset-react"
]
}

这是我的package.json

import React from 'react';

import app from '../src/app.react.js';

describe('App Snapshot', () => {
  test('renders', () => {
    const component = renderer.create(
      <app />
    );
    let tree = component.toJSON();
    expect(tree).toMatchSnapshot();
  });
});

这是我要测试的app.react.js文件

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@babel/preset-react": "^7.0.0",
    "@material-ui/core": "^1.5.0",
    "axios": "^0.18.0",
    "babel-preset-react": "^6.24.1",
    "chart.js": "^2.7.2",
    "jest": "^24.1.0",
    "js-cookie": "^2.2.0",
    "material-icons": "^0.2.3",
    "qrcode.react": "^0.9.2",
    "react": "^16.4.2",
    "react-chartjs-2": "^2.7.4",
    "react-dom": "^16.4.2",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^1.1.4",
    "universal-cookie": "^3.0.4",
    "unix-timestamp": "^0.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "jest",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.3.4",
    "@babel/preset-env": "^7.3.4",
    "flow-bin": "^0.78.0"
  }
}

1 个答案:

答案 0 :(得分:0)

您的代码看起来像TypeScript,因此将@babel/preset-typescript中的presets添加到.babelrc中。
哦,那您就不需要preset-env