4
votes

Many people seem to have experienced a version of this issue but none of the prior solutions seem to be working for me. My app is built with CRA and React Native Web. I am testing the click behavior of a component based on View from react native. I attempting to import { fireEvent } from '@testing-library/react-native', because fireEvent from @testing-library/react does not work but it throws this error: ReferenceError: DEV is not defined

package.json

{
  "name": "writual",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@fortawesome/fontawesome-free": "^5.12.1",
    "@fortawesome/fontawesome-svg-core": "^1.2.27",
    "@fortawesome/free-solid-svg-icons": "^5.12.1",
    "@fortawesome/react-fontawesome": "^0.1.8",
    "@n8tb1t/use-scroll-position": "^1.0.43",
    "@react-mock/localstorage": "^0.1.2",
    "@react-native-community/masked-view": "^0.1.7",
    "@react-pdf/renderer": "^1.6.8",
    "aphrodite": "^2.4.0",
    "babelify": "^10.0.0",
    "blob-stream": "^0.1.3",
    "browserify": "^16.5.0",
    "draft-js": "^0.11.4",
    "draft-js-plugins-editor": "^3.0.0",
    "draft-js-static-toolbar-plugin": "^3.0.1",
    "expo": "^36.0.2",
    "expo-cli": "^3.11.9",
    "firebase": "^7.9.1",
    "g": "^2.0.1",
    "lodash.debounce": "^4.0.8",
    "mutationobserver-shim": "^0.3.7",
    "pdfkit": "^0.10.0",
    "react": "^16.13.1",
    "react-art": "^16.12.0",
    "react-dom": "^16.11.0",
    "react-fns": "^1.4.0",
    "react-google-button": "^0.7.0",
    "react-google-login": "^5.1.1",
    "react-native": "^0.61.5",
    "react-native-draggable": "^3.3.0",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-movable-view": "^1.0.3",
    "react-native-multi-select-picker": "^1.0.11",
    "react-native-multiple-select": "^0.5.5",
    "react-native-popup-menu": "^0.15.7",
    "react-native-responsive-screen": "^1.4.0",
    "react-native-sectioned-multi-select": "^0.7.7",
    "react-native-vector-icons": "^6.6.0",
    "react-native-web": "^0.12.1",
    "react-pdfmake": "^0.2.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.3.1",
    "react-with-firebase-auth": "^1.3.0",
    "recyclerlistview": "^3.0.0",
    "socket.io": "^2.3.0",
    "typescript": "^3.7.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build-web": "react-scripts build",
    "test-web": "react-scripts test",
    "eject-web": "react-scripts eject",
    "start-native": "expo start",
    "android": "expo android",
    "ios": "expo ios",
    "build:ios": "expo build:ios",
    "build:android": "expo build:android"
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@testing-library/jest-dom": "^5.11.1",
    "@testing-library/react": "^10.4.7",
    "@testing-library/react-native": "^5.0.3",
    "@testing-library/user-event": "^12.0.12",
    "babel-plugin-module-resolver": "^4.0.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx-source": "^6.22.0",
    "babel-preset-expo": "^8.0.0",
    "css-loader": "^3.6.0",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1",
    "enzyme-to-json": "^3.3.5",
    "firebase-mock": "^2.3.2",
    "mock-local-storage": "^1.1.14",
    "style-loader": "^1.2.1"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!(react-native|react-native-responsive-screen|draft-js-static-toolbar-plugin|react-google-button')/)"
    ],
    "moduleFileExtension": [
      "js",
      "json",
      "jsx",
      "ts",
      "tsx",
      "node"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    },
    "globals": {
      "DEV": true
    },
    "verbose": true,
    "preset": "react-native"
  }
}

babelrc

{
  "presets": [
    "babel-preset-expo"
  ],
  "env": {
    "development": {
      "plugins": [
        "transform-object-rest-spread",
        "transform-react-jsx-source",
      ]
    }
  },
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "^react-native$": "react-native-web",
        }
      },
    ]
  ]
}
1
Were you able to get this to work?Cannon Moyer

1 Answers

0
votes

It seems you have DEV instead of __DEV__ in your package.json:

// ...
  "jest": {
  // ...
    "globals": {
      "__DEV__": true
    },
  // ...
  }
// ...