Jest Ionic测试失败-意外导入令牌

问题描述 投票:6回答:1

我不确定为什么将GA导入单元测试失败。我该如何解决?

也许是JEST错误应该使我指向正确的方向,但不幸的是,它没有:

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

....

/Users/me/app/node_modules/@ionic-native/google-analytics/index.js:20
    import { Injectable } from '@angular/core';
    ^^^^^^

    SyntaxError: Unexpected token import

      2 | import { Http } from '@angular/http';
      3 | import { Events } from 'ionic-angular';
    > 4 | import { GoogleAnalytics } from '@ionic-native/google-analytics';

根据指示,我将package.json扩展为

"transformIgnorePatterns": [
  "<rootDir>/node_modules"
],

但是它仍然失败,并出现相同的错误

angularjs unit-testing ionic-framework ionic3 jestjs
1个回答
0
投票

我想我已经找到了解决这个问题的方法,

  1. 不要在代码库中运行npm run eject,>
  2. 您可以在package.json测试命令中通过以下标志,--env=jsdom --transformIgnorePatterns 'node_modules/(?!(@ionic|<other-package-need-to-transform>)/)
  3. 此溶液对于离子/反应和离子/角是通用的

© www.soinside.com 2019 - 2024. All rights reserved.