Описание
Даже после принудительного jest.config.js
компиляции react-native-screens
в transformIgnorePatterns
в операторе импорта все равно не получается.
Технический стек
Мы инициализированы Реактивное приложение через выставку. Мы используем jest в качестве нашей среды модульного тестирования, поддерживаемой babel.
Журнал ошибок
/<usr_path>/node_modules/react-native-screens/src/screens.native.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';
^^^^^^
SyntaxError: Cannot use import statement outside a module
пакет. json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest"
},
"dependencies": {
"expo": "~36.0.0",
"react": "~16.9.0",
"react-dom": "^16.12.0",
"react-native": "^0.61.5",
"react-native-maps": "0.26.1",
"react-native-safe-area-context": "0.6.0",
"react-native-web": "^0.12.1",
"react-navigation": "^4.1.1",
"react-navigation-stack": "^2.1.1",
"react-native-screens": "2.0.0-alpha.20",
"react-native-gesture-handler": "~1.5.0",
"@react-native-community/masked-view": "0.1.5"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"babel-jest": "24.9.0",
"babel-preset-expo": "~8.0.0",
"jest-expo": "^36.0.1",
"jest-fetch-mock": "3.0.1",
"react-test-renderer": "^16.12.0"
},
"private": true
}
babel.config. js
module.exports = {
presets:
[
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"babel-preset-expo"
],
plugins:
[
"@babel/plugin-proposal-class-properties"
]
};
jest.config. js
module.exports = {
// All imported modules in your tests should be mocked automatically
automock: false,
clearMocks: true,
coverageDirectory: "coverage",
preset: "jest-expo",
testEnvironment: "node",
transform: {
"^.+\\.jsx?$": "babel-jest"
},
transformIgnorePatterns: [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|sentry-expo|native-base|react-native-screens)",
"screens/.*",
],
};