vendredi 29 novembre 2019

Error when unit testing on angular component that uses openlayers 6.1.1

I'm trying to run test on a angular app. The tests fails on an external module openlayers import.

I have an error when i want to import TileLayer and I running tests (This code is on a service that is included by dependency injection. Also I'm simply trying to test the creation of the gis.component.ts).

gis.component.ts :

export class GisComponent implements OnInit {
  constructor(private readonly gisService: GisService) {}

  ngOnInit() {
    this.gisService.renderMapOnHTML('map-container');
  }
}

gis.service.ts :

import TileLayer from 'ol/layer/Tile';
//...
@Injectable({
  providedIn: 'root',
})
export class GisService {
  //...
}

Error: The import works good but it fail when i run tests

 FAIL  apps/aims/src/app/components/shared/gis/gis.component.spec.ts
  ● Test suite failed to run

    /home/mehdi/Documents/Developpement/eams/front/workspace/node_modules/ol/layer/Tile.js:17
    import BaseTileLayer from './BaseTile.js';
           ^^^^^^^^^^^^^

    SyntaxError: Unexpected identifier
      1 | import { Injectable } from '@angular/core';
    > 2 | import TileLayer from 'ol/layer/Tile';
        | ^
      3 | import Map from 'ol/Map';
      4 | import OSM from 'ol/source/OSM';
      5 | import View from 'ol/View';

      at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
      at Object.<anonymous> (src/app/services/gis/gis.service.ts:2:1)

I'm using :
- Angular 8.2.14
- Jest 8.4.6
- OpenLayers 6.1.1

Aucun commentaire:

Enregistrer un commentaire