Setting up AppComponent for testing


#1

Hello everyone,

I’m using Ionic 4 beta and I want to use Jasmine to test it. Ionic 4 comes with testing properties by default, but most of my tests are now failing because I’m using Ionic storage inside my app. So I looked at the providers array.

            providers: [
                {provide: StatusBar, useValue: statusBarSpy},
                {provide: SplashScreen, useValue: splashScreenSpy},
                {provide: Platform, useValue: platformSpy}
            ],

Now I can put Storage or IonicStorageModule.forroot() in there, but it seems jasmine wants some sort of an storage spy.
Where can I find more info on how to setup app.component.spec.ts in combination with ionic specific components?

AppComponent throws this error:

	Error: StaticInjectorError(DynamicTestModule)[Storage]: 
	  StaticInjectorError(Platform: core)[Storage]: 
	    NullInjectorError: No provider for Storage!
	    at NullInjector.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:1360:19)
	    at resolveToken (webpack:///./node_modules/@angular/core/fesm5/core.js?:1598:24)
	    at tryResolveToken (webpack:///./node_modules/@angular/core/fesm5/core.js?:1542:16)
	    at StaticInjector.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:1439:20)
	    at resolveToken (webpack:///./node_modules/@angular/core/fesm5/core.js?:1598:24)
	    at tryResolveToken (webpack:///./node_modules/@angular/core/fesm5/core.js?:1542:16)
	    at StaticInjector.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:1439:20)
	    at resolveNgModuleDep (webpack:///./node_modules/@angular/core/fesm5/core.js?:8667:29)
	    at NgModuleRef_.get (webpack:///./node_modules/@angular/core/fesm5/core.js?:9355:16)
	    at inject (webpack:///./node_modules/@angular/core/fesm5/core.js?:1701:33)

At should create the app, should initialize the app, should have menu labels, should have urls


#2

What I do is mock Storage with a class that is simply backed by a Map.


#3

So just use a map for key/value approach like storage does? Could you please give a hint on how to do that?