lundi 27 janvier 2020

Testing amcharts 4 in angular 8 using jest

Trying to test a Angular 8 component using Jest that has a graph on it using amcharts. The only solution I have found is specific for React (React Solution). It seems to be failing when Jest runs it uses node modules, so before I think it is possible to implement a mock for the relevant imports.

Any ideas?

Error message:

Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

export { System, system } from "./.internal/core/System";
    ^^^^^^

    SyntaxError: Unexpected token 'export'

       8 |   OnChanges,
       9 | } from '@angular/core';
    > 10 | import * as am4core from '@amcharts/amcharts4/core';
         | ^
      11 | import * as am4charts from '@amcharts/amcharts4/charts';
      12 | import am4themes_animated from '@amcharts/amcharts4/themes/animated';
      13 | import { Moment } from 'moment';

      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)

Aucun commentaire:

Enregistrer un commentaire