我不确定为什么将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"
],
但是它仍然失败,并出现相同的错误
我想我已经找到了解决这个问题的方法,
npm run eject
,>package.json
测试命令中通过以下标志,--env=jsdom --transformIgnorePatterns 'node_modules/(?!(@ionic|<other-package-need-to-transform>)/)
此溶液对于离子/反应和离子/角是通用的