ionic-team / ionic-storage

Ionic Storage module for Ionic apps
MIT License
434 stars 99 forks source link

TypeError: Object prototype may only be an Object or null: undefined using Jest for unit tests #225

Open vicphase opened 3 years ago

vicphase commented 3 years ago

When importing Storage from @ionic/storage-angular the following error appears running unit tests with Jest:

  ā— Test suite failed to run

    TypeError: Object prototype may only be an Object or null: undefined
        at setPrototypeOf (<anonymous>)

      2 | import { StatusBar } from '@ionic-native/status-bar/ngx';
      3 | import { Platform } from '@ionic/angular';
    > 4 | import { Storage } from '@ionic/storage-angular';
        | ^
      5 | import { ThemeService } from '@ivt/u-ui';
      6 | import { createComponentFactory, Spectator } from '@ngneat/spectator';
      7 | import { provideMockStore } from '@ngrx/store/testing';

      at extendStatics (../../node_modules/@ionic/storage-angular/bundles/ionic-storage-angular.umd.js:27:16)
      at __extends (../../node_modules/@ionic/storage-angular/bundles/ionic-storage-angular.umd.js:31:9)
      at ../../node_modules/@ionic/storage-angular/bundles/ionic-storage-angular.umd.js:228:9
      at ../../node_modules/@ionic/storage-angular/bundles/ionic-storage-angular.umd.js:290:6
      at ../../node_modules/@ionic/storage-angular/bundles/ionic-storage-angular.umd.js:2:68
      at Object.<anonymous> (../../node_modules/@ionic/storage-angular/bundles/ionic-storage-angular.umd.js:5:2)
      at Object.<anonymous> (src/app/app.component.spec.ts:4:1)

To reproduce this issue you'll need to add this to your jest.preset

  transformIgnorePatterns: [
    'node_modules/(?!@ngrx|@ionic-native|@ionic)'
  ]

Also this configuration is needed on your tsconfig.spec.ts compiler options

    "module": "commonjs",
    "target": "es5",
    "allowJs": true

It would be great if this can be fixed! Thanks guys šŸ˜„

eweap commented 2 years ago

Same problem here with jest 27 Is there any workaround ?

Thanks

Adam966 commented 2 years ago

Hi I have same problem did anyone found some solution for this?

villarzz commented 2 years ago

same problem, someone know how to fix?