1.

Explain briefly unit testing in Ionic 4.

Answer»

Ionic 4 being based on Angular 6 / 7 , the application when created comes with a UNIT testing framework named Jasmine. It is automatically set up up to unit test the application. Unit tests are CONTAINED in .SPEC files which are created for every component, page, service , pipe, guard etc. The spec file contains a single describe call that defines the overall test. 

Each describe call can contain setup and teardown code through before Each and after Each calls. Finally, it calls define individual test cases. 

Below snippet shows a sample spec.ts file for a page. 

describe('Tab1Page', () =&GT; {  let component: Tab1Page;  let fixture: ComponentFixture<Tab1Page>;  beforeEach(async(() => {  TestBed.configureTestingModule({  declarations: [Tab1Page],  schemas: [CUSTOM_ELEMENTS_SCHEMA],  }).compileComponents();  }));  beforeEach(() => {  fixture = TestBed.createComponent(Tab1Page);  component = fixture.componentInstance;  fixture.detectChanges();  });  it('should create', () => {  expect(component).toBeTruthy();  });  });


Discussion

No Comment Found