I am performing unit testing on Ionic2, using Karma/Jasmine. How to write specs for ion-title and ion-content?Will it be similar to how I wrote for h4 tag?
And can we make the custom mocks for using in the test? homePage.html
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
The world is your oyster.
<p>
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
</p>
<h4>Testing</h4>
</ion-content>
homePage.spec.ts
import { async, TestBed, ComponentFixture } from "@angular/core/testing";
import { HomePage } from "./home";
import { IonicModule, NavController } from "ionic-angular";
import { DebugElement } from "@angular/core";
import { By } from "@angular/platform-browser";
describe('HomePage', () => {
let fixture: ComponentFixture<HomePage>;
let comp: HomePage;
let de: DebugElement;
let el: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [HomePage],
imports: [
IonicModule.forRoot(HomePage)
],
providers: [
NavController
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HomePage);
comp = fixture.componentInstance;
de = fixture.debugElement.query(By.css('h4'));
el = de.nativeElement;
});
it('initializes', () => {
expect(fixture).toBeTruthy();
expect(comp).toBeDefined();
});
it('checks for the h4 element in the DOM', () => {
fixture.detectChanges();
expect(el.textContent).toContain('Testing');
});
it('checks the ion-title', ()=>{
//how to write a test case for checking ion-title,
ion-content?
});
});