Search code examples
node.jsintellij-ideaionic-frameworkcordova-pluginsionic2

Ionic unit testing geolocation fails


Trying to unit test my new ionic2 application fails after adding the geolocation test cases. Here is a minimum example: https://github.com/geoHeil/ioni2GeolocationUnitTest

The error can be reproduced by running npm test

TypeScript error: app/services/geo/geolocation.service.spec.ts(30,38): Error TS2339: Property 'Coordinates' does not exist on type 'typeof ".../node_modules/ionic-native/dist/plugins/geolocation"'.

strangely even though I specified:

import  * as NativeGeo  from 'ionic-native/dist/plugins/geolocation';

this type definition seems to be used

/Applications/IntelliJ\ IDEA\ 2016.2\ EAP.app/Contents/plugins/JavaScriptLanguage/typescriptCompiler/external/lib.d.ts

edit

I just found Geolocation unit test with JsTestDriver which might be slightly related


Solution

  • I fixed it creating my own implementation of coordinates, like:

    class MyCoordinates implements Coordinates {
        latitude: number;
        longitude: number;
        accuracy: number;
        altitude: number;
        altitudeAccuracy: number;
        heading: number;
        speed: number;
    }