onPageLoaded and Unit Testing

Hello everyone,

I started writing tests for our application. For the most of the components we use the onPageLoaded event, as the content has to be cached.

Now my question is, how do I get into the onPageLoaded event and mock what is in there? That is a sample code I would like to unit test:

@Component({
    templateUrl: "build/pages/subjects/subjects.html"
})
export class SubjectsComponent extends ComponentBase<SubjectModel> {
    constructor(nav: NavController, params: NavParams, backendService: BackendService) {
        super(nav, params, backendService);
    }

    public selectSubject(target: string) {
        this.nav.push(TopicsComponent, { target: target });
    }

    protected onPageLoaded(): void {
        this.loadNavigation("a0000000", (condition) => {
            let model = new SubjectModel();
            model.title = condition.title;
            model.target = condition.target;

            this.models.push(model);
        });
    }
}

The loadNavigation() method is in the base class. It calls a backend service which I would like to mock.

Any one has already done this here?

So, what I did to fix this for now was to modify onPageLoaded to be public and in my test I called the method onPageLoaded which in my opinion is not so chic.

So I found the solution. I kept the onPageLoaded method as protected and in my test that is how I did the call:

    // Act
    var component = new SubjectsComponent(navController, navParams, backendService);

    component["onPageLoaded"]();