Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

javascript - 对使用openlayers 6.1.1的角度组件进行单元测试时出错(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.

(测试在外部模块openlayers导入上失败。)



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).

(当我想导入TileLayer并运行测试时出现错误(此代码位于依赖注入所包含的服务上。另外,我只是在尝试测试gis.component.ts的创建)。)

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 :

(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

(-角度8.2.14)


- Jest 8.4.6

(-开玩笑8.4.6)


- OpenLayers 6.1.1

(-OpenLayers 6.1.1)


  ask by Mehdi Kml translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...