Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Super expression must either be null or a function #1734

Open
pankajnegi1893 opened this issue Jan 16, 2024 · 3 comments
Open

TypeError: Super expression must either be null or a function #1734

pankajnegi1893 opened this issue Jan 16, 2024 · 3 comments

Comments

@pankajnegi1893
Copy link

I am getting below error when running my test case

Test suite failed to run

    TypeError: Super expression must either be null or a function

      13 |   @field('modified') modified!: string;
      14 |
    > 15 |   @field('whatsapp_setting_id') whatsappSettingId!: string;
         |                                ^
      16 | }
      17 |
      18 | export default ChatSettings;

      at _inherits (node_modules/@babel/runtime/helpers/inherits.js:4:11)
      at src/db/modals/ChatSettings.ts:15:32
      at Object.<anonymous> (src/db/modals/ChatSettings.ts:15:32)
      at Object.require (src/db/index.ts:3:1)
      at Object.require (src/db/controller/MessageDBController.ts:2:1)
      at Object.require (src/screens/WhatsappChat/Message.tsx:13:1)
      at Object.require (navigation/StackNavigators/AccountStack.tsx:30:1)
      at Object.require (navigation/StackNavigators/__tests__/AccountStack.test.tsx:6:1)

I have checked regarding this error but still getting same issue. below are the babel.config.js file I am having.

babel.config.js

module.exports = {
  presets: [
    'module:metro-react-native-babel-preset',
    '@babel/preset-typescript',
  ],
  plugins: [
    '@babel/plugin-proposal-export-namespace-from',
    'react-native-reanimated/plugin',
    ['@babel/plugin-proposal-decorators', {legacy: true}],
    ['@babel/plugin-proposal-class-properties', {loose: true}],
    [
      '@babel/plugin-transform-runtime',
      {
        helpers: true,
        regenerator: true,
      },
    ],
  ],
  env: {
    production: {
      plugins: ['transform-remove-console'],
    },
  },
};

tsconfig.json

{
"extends": "@tsconfig/react-native/tsconfig.json",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"paths": {
// this allows sub-package imports from src; fx. '@nozbe/watermelondb/decorators'
"@nozbe/watermelondb/": ["./src/db/"]
}
},
"include": [
"./*.ts",
"./src/
/*.ts" // this is just used to validate everything, not just imported declarations
]
}**

package.json

"@nozbe/watermelondb": "^0.27.1",
"@nozbe/with-observables": "^1.6.0",

@pankajnegi1893
Copy link
Author

After putting below code in jest setup file. it's working fine.

export const mockDatabase = {
  collections: {
    get: jest.fn(),
  },
};

jest.mock('@nozbe/watermelondb', () => ({
  ...jest.requireActual('@nozbe/watermelondb'),
  Modal: jest.fn(),
  Database: jest.fn(() => mockDatabase),
  Q: {
    sqlite: {
      openDatabase: jest.fn(),
    },
  },
}));

@MuhammadNaumanShafique
Copy link

After putting below code in jest setup file. it's working fine.

export const mockDatabase = {
  collections: {
    get: jest.fn(),
  },
};

jest.mock('@nozbe/watermelondb', () => ({
  ...jest.requireActual('@nozbe/watermelondb'),
  Modal: jest.fn(),
  Database: jest.fn(() => mockDatabase),
  Q: {
    sqlite: {
      openDatabase: jest.fn(),
    },
  },
}));

@pankajnegi1893 I have tried your solution but I'm getting this error:

TypeError: Cannot read properties of undefined (reading 'getRandomIds')

Screenshot 2024-02-02 at 5 26 08 PM

Do you have any idea how to fix this?

@estebanfm
Copy link

@MuhammadNaumanShafique I had the same error and updating to 0.27.1 fixed it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants