Solving the Ionic 2 Unit Testing error “TypeError: null is not an object (evaluating ‘this._scroll.ev’)”

Ionic 2 Unit Testing

Posted on February 11, 2017

Tags:

Ionic

Setting up the unit testing for your Ionic 2 project is actually quite simple. Despite this I had an issue with one of my tests failing with the error TypeError: null is not an object (evaluating ‘this._scroll.ev’).

A Quick search of Google and it seems to be a common issue but nobody had posted a definitive answer/fix.

It’s actually just a case of importing ViewController from ionic-angular, adding it to your providers array and creating a new instance of ViewController:

import { IonicModule, NavController, ViewController } from 'ionic-angular';
TestBed.configureTestingModule( {
    providers: [
        { provide: ViewController, useValue: new ViewController() }
    ]
} ).compileComponents();