lundi 2 mars 2020

Expected spy StatusBar.styleDefault to have been called and Expected spy SplashScreen.hide to have been called errors getting when run ng test command

Expected spy StatusBar.styleDefault to have been called and Expected spy SplashScreen.hide to have been called errors getting when run ng test command

I am using angular 6 and ionic 4 angular itself generated spec file when created pages and run test scripts by using ng test command it shows the ffollowing error.

Expected spy StatusBar.styleDefault to have been called. Expected spy SplashScreen.hide to have been called

and my app.component.spec.ts file:

          fdescribe('AppComponent', () => {

              let statusBarSpy, splashScreenSpy, platformReadySpy, platformSpy;

              beforeEach(async(() => {
                statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']);
                splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']);
                platformReadySpy = Promise.resolve();
                platformSpy = jasmine.createSpyObj('Platform', { ready: platformReadySpy });

                TestBed.configureTestingModule({
                  declarations: [AppComponent],
                  schemas: [CUSTOM_ELEMENTS_SCHEMA],
                  providers: [
                    { provide: StatusBar, useValue: statusBarSpy },
                    { provide: SplashScreen, useValue: splashScreenSpy },
                    { provide: Platform, useValue: platformSpy },
                  ],
                  imports: [MatSnackBarModule,MatMenuModule,IonicStorageModule.forRoot(),RouterTestingModule.withRoutes([])],
                }).compileComponents();
              }));

              it('should create the app', async () => {
                const fixture = TestBed.createComponent(AppComponent);
                const app = fixture.debugElement.componentInstance;
                expect(app).toBeTruthy();
              });

              it('should initialize the app', async () => {
                TestBed.createComponent(AppComponent);
                expect(platformSpy.ready).toHaveBeenCalled();
                await platformReadySpy;
                expect(statusBarSpy.styleDefault).toHaveBeenCalled();
                expect(splashScreenSpy.hide).toHaveBeenCalled();
              });

              it('should have menu labels', async () => {
                const fixture = await TestBed.createComponent(AppComponent);
                await fixture.detectChanges();
                const app = fixture.nativeElement;
                const menuItems = app.querySelectorAll('ion-label');
                expect(menuItems.length).toEqual(2);
                expect(menuItems[0].textContent).toContain('Home');
                expect(menuItems[1].textContent).toContain('List');
              });

              it('should have urls', async () => {
                const fixture = await TestBed.createComponent(AppComponent);
                await fixture.detectChanges();
                const app = fixture.nativeElement;
                const menuItems = app.querySelectorAll('ion-item');
                expect(menuItems.length).toEqual(2);
                expect(menuItems[0].getAttribute('ng-reflect-router-link')).toEqual('/home');
                expect(menuItems[1].getAttribute('ng-reflect-router-link')).toEqual('/list');
              });

            });

Aucun commentaire:

Enregistrer un commentaire