jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.05k stars 6.44k forks source link

jest-with-react-native-getting-issue #3234

Closed somsin closed 7 years ago

somsin commented 7 years ago

http://stackoverflow.com/questions/43137058/jest-with-react-native-getting-issue

({"Object.":function(module,exports,require,dirname,filename,global,jest){import React, { Component, Children, PropTypes } from 'react'; ^^^^^^ SyntaxError: Unexpected token import

  at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:320:12)
  at Object.<anonymous> (node_modules/react-native-root-siblings/lib/AppRegistryInjection.js:3:22)
  at Object.<anonymous> (node_modules/react-native-root-siblings/lib/SiblingsManager.js:3:27)
thymikee commented 7 years ago

It looks like some modules are not transformed through babel properly. I think you should reach out to react native repo, as they're maintaining preset with Jest configuration.

somsin commented 7 years ago

i knew that modules are not transformed through babel properlybut how to resolve this . whare and what i have to change

thymikee commented 7 years ago

There's an answer on SO: https://stackoverflow.com/questions/43137058/jest-with-react-native-getting-issue

NeelamSoni129 commented 5 years ago

I am also getting the same issue : `({"Object.":function(module,exports,require,dirname,filename,global,jest){import 'react-native'; ^^^^^^

SyntaxError: Unexpected token import`

My package.json file :

`{
  "name": "my_project",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start --port 8082 --reset-cache",
    "android": "react-native run-android --port 8082",
    "test": "jest",
    "lint": "eslint app | snazzy",
    "lintdiff": "git diff --name-only --cached --relative | grep '\\.js$' | xargs eslint app | snazzy",
    "fixcode": "eslint --fix app"
  },
  "dependencies": {
    "@babel/core": "7.0.0-beta.54",
    "@expo/vector-icons": "^6.3.1",
    "axios": "^0.18.0",
    "babel-bridge": "^1.12.11",
    "babel-core": "7.0.0-bridge.0",
    "babel-preset-react-native": "^4.0.1",
    "babel-runtime": "^7.0.0-beta",
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.6.0",
    "enzyme-to-json": "^3.3.4",
    "eslint": "^3.17.1",
    "eslint-config-standard": "^7.0.1",
    "eslint-config-standard-flow": "^1.0.1",
    "eslint-plugin-promise": "^3.5.0",
    "eslint-plugin-standard": "^2.1.1",
    "jest-cli": "^23.6.0",
    "jest-environment-node": "^23.4.0",
    "jest-resolve": "^23.6.0",
    "jsencrypt": "^3.0.0-rc.1",
    "moment": "^2.22.2",
    "moment-timezone": "^0.5.21",
    "native-base": "^2.7.2",
    "react": "16.3.1",
    "react-addons-test-utils": "^15.6.2",
    "react-dom": "^16.5.2",
    "react-moment": "^0.7.9",
    "react-native": "0.55.4",
    "react-native-android-settings-library": "^1.0.5",
    "react-native-carousel-view": "^0.5.1",
    "react-native-device-info": "^0.22.5",
    "react-native-image-crop-picker": "^0.21.2",
    "react-native-loader": "1.2.1",
    "react-native-popover-tooltip": "^1.1.4",
    "react-native-progress-circle": "^2.0.0",
    "react-native-responsive-screen": "^1.1.9",
    "react-native-signature-capture": "^0.4.9",
    "react-native-user-inactivity": "0.0.1-beta.1",
    "react-native-vector-icons": "^5.0.0",
    "react-navigation": "^2.3.1",
    "react-navigation-redux-helpers": "^2.0.5",
    "react-redux": "5.0.7",
    "redux": "4.0.0",
    "redux-form": "^7.4.2",
    "redux-logger": "3.0.6",
    "redux-thunk": "2.3.0",
    "save": "2.3.2"
  },
  "devDependencies": {
    "babel-jest": "^23.6.0",
    "babel-preset-react-native": "^4.0.0",
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.6.0",
    "enzyme-to-json": "^3.3.4",
    "jest": "^23.6.0",
    "jest-react-native": "^18.0.0",
    "react-test-renderer": "^16.5.2",
    "redux-mock-store": "^1.5.3",
    "regenerator-runtime": "^0.12.1"
  },
  "jest": {
    "testEnvironment": "jsdom",
    "preset": "react-native",
    "transformIgnorePatterns": [
    "node_modules/?!react-native|react-navigation|native-base|jsencrypt|(?!native-base-shoutem-theme)|@shoutem/theme|@shoutem/animation|@shoutem/ui|tcomb-form-native"
    ],
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/app/quality/__mocks__/fileMock.js",
      "\\.(css|less)$": "<rootDir>/app/quality/__mocks__/styleMock.js"
    },
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "setupFiles": [
      "<rootDir>/app/jest/setup.js"
    ],
    "transform": {
      "^.+\\.jsx?$": "babel-jest",
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
      "^.+\\.(js|jsx)$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    }
  },
  "rnpm": {
    "assets": [
      "./app/assets/fonts/"
    ]
  },
  "config": {
    "ghooks": {
      "pre-commit": "if [ -d 'ignite-base' ]; then cd ignite-base; fi;  npm run fixcode && git add . && npm run lint"
    }
  }
}
`
ghost commented 5 years ago

Answer: https://github.com/react-navigation/react-navigation/issues/256#issuecomment-278626369

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.