AsyncStorage类的流类型的玩笑问题

时间:2018-09-29 21:10:25

标签: react-native jestjs

我相信这是一个设置错误,但是我不知道该怎么办了,我尝试了很多东西。我们有一个应用程序设置,测试失败并显示错误:

src/__tests__/App.spec.tsx
  ● Test suite failed to run

    SyntaxError: .../react-native/Libraries/Storage/AsyncStorage.js: Unexpected token, expected "," (31:19)

      29 |  */
      30 | const AsyncStorage = {
    > 31 |   _getRequests: ([]: Array<any>),
         |                    ^
      32 |   _getKeys: ([]: Array<string>),
      33 |   _immediate: (null: ?number),
      34 | 

      at Parser.raise (node_modules/@babel/core/node_modules/babylon/lib/index.js:776:15)
      at Parser.unexpected (node_modules/@babel/core/node_modules/babylon/lib/index.js:2079:16)
      at Parser.expect (node_modules/@babel/core/node_modules/babylon/lib/index.js:2067:28)
      at Parser.parseParenAndDistinguishExpression (node_modules/@babel/core/node_modules/babylon/lib/index.js:3283:14)
      at Parser.parseExprAtom (node_modules/@babel/core/node_modules/babylon/lib/index.js:3113:21)
      at Parser.parseExprSubscripts (node_modules/@babel/core/node_modules/babylon/lib/index.js:2757:21)
      at Parser.parseMaybeUnary (node_modules/@babel/core/node_modules/babylon/lib/index.js:2736:21)
      at Parser.parseExprOps (node_modules/@babel/core/node_modules/babylon/lib/index.js:2643:21)
      at Parser.parseMaybeConditional (node_modules/@babel/core/node_modules/babylon/lib/index.js:2615:21)
      at Parser.parseMaybeAssign (node_modules/@babel/core/node_modules/babylon/lib/index.js:2562:21)

这是App.spec.tsx代码:

import React from 'react';
import renderer from 'react-test-renderer';

import { App } from '../app';

it('renders correctly with defaults', () => {
  const app = renderer.create(<App />).toJSON();
  expect(app).toMatchSnapshot();
});

我的jest.json:

{
  "preset": "react-native",
  "cacheDirectory": ".jest/cache",
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
  "moduleFileExtensions": [
    "ts",
    "tsx",
    "js"
  ],
  "transform": {
    "^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
    "\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
  },
  "transformIgnorePatterns": [
    "node_modules/(?!(jest-)?react-native|react-navigation)"
  ],
  "testPathIgnorePatterns": [
    "\\.snap$",
    "<rootDir>/node_modules/",
    "<rootDir>/lib/",
    "./build"
  ],
  "globals": {
    "window": true
  }
}

我可以提供任何有用的信息吗?这是流类型的问题,巴别尔...?我的.babelrc非常简单。

0 个答案:

没有答案