意外的令牌{在Jest测试中

时间:2018-12-27 11:14:23

标签: reactjs testing jestjs

我开始学习Jest测试框架,并尝试使用npm test做简单的测试,但是我遇到了这个错误:

enter image description here

我正在尝试将import更改为require,但这没有帮助:(关于如何处理此错误的任何建议?

这也是我的package.json文件部分,与

相关
devDependencies and jest:
{
    "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.6.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "jest": "^22.4.3",
    "parcel-bundler": "^1.11.0"
  },
  "jest": {
    "verbose": true,
    "testURL": "http://localhost:1234/"
  }
}

1 个答案:

答案 0 :(得分:0)

1. Importing default export: Every module is said to have at most one default 
   export. In order to import the default export from a file, we can give a
   name to the import making the syntax as the following.

   import GIVEN_NAME from ADDRESS

2. Importing named values: Every module can have several named parameters and 
   in order to import one we should use the syntax as follows.

   import { PARA_NAME } from ADDRESS

   And similarly for multiple such imports we can use a comma to seperate two 
   parameter name within the curly braces.
3. Importing a combination of Default Exports and Named Values: The title 
   makes it clear what we need to see is that the syntax of the same. In order 
   to import a combination, we should use the following syntax.

   import GIVEN_NAME, { PARA_NAME, ... } from ADDRESS