Как отлаживать тест-кейсы React jest - PullRequest
0 голосов
/ 19 ноября 2018

Когда я пытаюсь отладить тесты Rect Jest для энзимов в терминале, я получаю следующую ошибку и застреваю из-за этого.

Я создал приложение, используя create-реагировать-приложение, и моя конфигурация следующая:

.babelrc

{
  "env": {
    "test": {
      "sourceMaps": "inline",
      "presets": ["es2015", "react-app"],
      "plugins": ["transform-export-extensions"],
      "only": [
        "./**/*.js",
        "node_modules/jest-runtime"
      ]
    }
  }
}

Конфигурация Jest от package.json

"jest": {
    "testMatch": [
      "**/src/**/?(*.)(spec|test).js?(x)"
    ],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "moduleFileExetnsions": [
      "ts",
      "txx",
      "js",
      "json"
    ],
    "transform": {
      "^.+\\.jsx$": "babel-jest",
      "^.+\\.js$": "babel-jest"
    }
}

Контрольный пример:

import { shallow } from 'enzyme';
import App from './App';
describe('App', () => {
  it('should render app', () => {

    const component = shallow(<App />);

    expect(component).toMatchSnapshot();
  });
});

Получение следующей ошибки:

Test suite failed to run

    ReferenceError: [BABEL] .../src/containers/App.spec.js: Unknown option: /node_modules/babel-preset-react-app/index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.

    A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

    Invalid:
      `{ presets: [{option: value}] }`
    Valid:
      `{ presets: [['presetName', {option: value}]] }`

    For more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options. (While processing preset: "/node_modules/babel-preset-react-app/index.js")

      at Logger.error (node_modules/babel-core/lib/transformation/file/logger.js:41:11)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:226:20)
      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)
      at OptionManager.mergePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
      at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)

Редактировать:

Вышла ошибка после изменения «test» -> «dev» в.babelrc, но появляется другая ошибка:

"Jest обнаружил неожиданный токен" на мелком уровне ();

1 Ответ

0 голосов
/ 19 ноября 2018

Попробуйте использовать это .babel config:

{
   "presets": ["es2015", "react-app"],
   "plugins": ["transform-export-extensions"],
   "only": [
     "./**/*.js",
     "node_modules/jest-runtime"
   ]
}

Это должно помочь вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...