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