jestjs / jest

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

Cannot convert undefined or null to object at jest in react native application #11618

Closed pranava3812 closed 2 years ago

pranava3812 commented 3 years ago

Recently we did migration in react-native from 0.59 to 0.63 and updated all required modules as well. Post that all the test cases are failing with below error. For reference added all config details. FAIL src/assets/IconSun.test.tsx ● Test suite failed to run

TypeError: Cannot convert undefined or null to object
    at assign (<anonymous>)

  at _extends (node_modules/@babel/runtime/helpers/extends.js:17:19)
  at Object.user:node_modules/react-native/Libraries/Renderer/shims/ReactNative.js: (node_modules/@testing-library/react-native/dist/preset/mock-modules.js:41:25)
  at Object.<anonymous> (node_modules/react-native/Libraries/Components/Touchable/Touchable.js:17:21)

babel.config.js

module.exports = { presets: ['module:metro-react-native-babel-preset'], };

jest.config.js const jestPreset = require('@testing-library/react-native/jest-preset');

const transformNodeModules = ['@rnc', 'react-native', 'react-native-svg', 'react-navigation'];

module.exports = { preset: '@testing-library/react-native', // transformIgnorePatterns: [node_modules/(?!(${transformNodeModules.join('|')})/)], transformIgnorePatterns: [ "node_modules/(?!(jest-)?react-native|react-(native|universal|navigation)-(.)|@react-native-community/(.)|@react-navigation/(.*)|bs-platform|@rootstrap/redux-tools)" ], setupFiles: [...jestPreset.setupFiles, '/src/setupTests.js'], collectCoverageFrom: ['/src/*/.{ts,tsx}'], coveragePathIgnorePatterns: ['/test-utils/'], coverageDirectory: './coverage', coverageThreshold: { global: { branches: 5, functions: 5, lines: 5, statements: 5, }, }, };

package json : "react-native": "0.63.4", "jest": "^24.8.0", "metro-react-native-babel-preset": "0.65.2", "babel-jest": "^24.8.0", "babel-loader": "^8.0.4",

tsconfig.json

{ "compilerOptions": { "rootDirs": ["src"], "outDir": "dist", "target": "es2017", "lib": ["es2018"], "module": "es2015", "moduleResolution": "node", "types": ["react", "react-native", "jest"], "jsx": "react-native", "declaration": true, "removeComments": true, "strict": true, "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noUnusedLocals": true, "allowSyntheticDefaultImports": true, "experimentalDecorators": true, "noImplicitAny": false, "sourceMap": true }, "include": ["typings/*.d.ts", "src/*/"], "exclude": [ "dist", "ios", "node_modules", "android", "/mocks", "/tests", "/.test.", "/test-utils", "index.js", "index.*.js" ] }

ConAntonakos commented 3 years ago

Facing this issue in Travis CI. Any idea what's happening?

$ node --version
v14.17.5
$ npm --version
6.14.14
$ nvm --version
0.38.0
$ yarn --version
1.22.4

yarn run v1.22.4
$ jest --runInBand
TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Object.<anonymous> (/home/travis/build/<project>/node_modules/jest-snapshot/node_modules/@babel/highlight/node_modules/chalk/index.js:73:28)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/home/travis/build/<project>/node_modules/jest-snapshot/node_modules/@babel/highlight/lib/index.js:14:15)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
error Command failed with exit code 1.
github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] commented 1 year 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.