jestjs / jest

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

TypeError: Cannot call a class as a function #2743

Closed octohedron closed 7 years ago

octohedron commented 7 years ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

My code is running fine in production but tests are not passing when importing an object from a file, error is: TypeError: Cannot call a class as a function at at _classCallCheck (node_modules/react-native/jest/mockComponent.js:9:616)

Object I'm importing:

export const Fabric = {
  Crashlytics: {
    logException: jest.fn(),
    setString: jest.fn(),
    setUserEmail: jest.fn(),
    recordError: jest.fn()
  },
  Answers: {
    logSignUp: jest.fn(),
    logException: jest.fn(),
    logCustom: jest.fn(),
    logLogin: jest.fn()
  },
};

import statement

const {Answers} = require('../../../test/setup').Fabric;

Commenting that line ^ makes the test pass

Just adding that import statement throws Cannot call a class as a function at at _classCallCheck (node_modules/react-native/jest/mockComponent.js:9:616)

The same import statement works fine in other files, this error happens running jest -u --runInBand, doesn't happen when running the code in production.

The actual test:

const tree = renderer.create(
      <MyComponent />
    ).toJSON();
expect(tree).toMatchSnapshot();

What is the expected behavior?

Test should pass or tell me what the real problem is.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

"jest": {
    "collectCoverageFrom": [
      "**/*.{js,jsx}",
    ],
    "haste": {
      "defaultPlatform": "ios",
      "platforms": [
        "android",
        "ios"
      ],
      "providesModuleNodeModules": [
        "react-native"
      ]
    },
    "globals": {
      "__TEST__": true
    },
    "moduleNameMapper": {
      "^image![a-zA-Z0-9$_-]+$": "GlobalImageStub",
      "^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$": "RelativeImageStub",
      "^React$": "<rootDir>node_modules/react",
      "\\./datepicker$": "<rootDir>/node_modules/tcomb-form-native/lib/templates/bootstrap/datepicker.ios.js",
      "\\./select$": "<rootDir>/node_modules/tcomb-form-native/lib/templates/bootstrap/select.ios.js"
    },
    "modulePathIgnorePatterns": [
      "<rootDir>/node_modules/react-native/Libraries/react-native/",
      "<rootDir>/node_modules/react-native/packager/",
      "<rootDir>/node_modules/react-native-fabric/"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|tcomb-form-native|react-clone-referenced-element)"
    ],
    "setupFiles": [
      "<rootDir>/node_modules/react-native/jest/setup.js"
    ],
    "testEnvironment": "node",
    "testResultsProcessor": "./node_modules/jest-junit",
    "collectCoverage": true,
    "verbose": false
  },

OS macOS Sierra 10.12.2 npm -v 3.10.8 node -v v6.7.0 jest ^18.1.0

octohedron commented 7 years ago

this line was breaking it: global.__DEV__ = false;

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.