Search code examples
unit-testingionic-frameworkionic2

Mock ionic-native for testing


I'm writing an ionic 2 app I'd like to test. Therefore, I need the ability to mock ionic native plugins, i.e. I want to test how the application reacts to network changes. I tried out to import the modules and override its properties:

import {Network, Connection} from 'ionic-native';
Network.connection = Connection.WIFI;

but this does not work ('Cannot set property connection of function Network() { } which has only a getter'). Is there any possibility to mock this?


Solution

  • This matter is being discussed here, and probably those classes with static methods will be replaced by injectable services.