Jest for React Native

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

/Users/betadmin/BettingForFootball/node_modules/react-native/jest/mockComponent.js:20
static displayName = 'Component';
^

SyntaxError: Unexpected token =

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
  at Object. (node_modules/react-native/jest/setup.js:13:31)

transformIgnorePatterns配制不对.
排队所有node_modules里的模块.
transformIgnorePatterns: ["node_modules/(?!(.+)/)"]

2.jest执行报错.
console.error node_modules/react-native/Libraries/YellowBox/YellowBox.js:59
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

● renders correctly

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

  at invariant (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:55:15)
  at invariant (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2054:11)
  at createFiberFromTypeAndProps (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:2075:15)
  at createFiberFromElement (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:4605:23)
  at reconcileSingleElement (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:4662:35)
  at reconcileChildFibers (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6329:28)
  at reconcileChildren (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6741:5)
  at updateHostRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7566:14)
  at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11234:12)
  at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11266:24)

你可能感兴趣的:(Jest for React Native)